Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect keys for predicted buckets in Moving Average Aggregation #11369

Closed
colings86 opened this issue May 27, 2015 · 1 comment · Fixed by #11375
Closed

Incorrect keys for predicted buckets in Moving Average Aggregation #11369

colings86 opened this issue May 27, 2015 · 1 comment · Fixed by #11375

Comments

@colings86
Copy link
Contributor

My query:

GET weatherdata/_search
{
  "size": 0,
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "element": {
              "value": "tmax"
            }
          }
        }
      ]
    }
  },
  "aggs": {
    "maxTMax": {
      "max": {
        "field": "value",
        "script": "_value / 10",
        "format": "###.##"
      }
    },
    "maxAvgTMaxMonth": {
      "max_bucket": {
        "buckets_path": "tMaxHisto>avgTMax",
        "format": "###.##"
      }
    },
    "minAvgTMaxMonth": {
      "min_bucket": {
        "buckets_path": "tMaxHisto>avgTMax",
        "format": "###.##"
      }
    },
    "tMaxHisto": {
      "date_histogram": {
        "field": "date",
        "interval": "quarter"
      },
      "aggs": {
        "avgTMax": {
          "avg": {
            "field": "value",
            "script": "_value / 10",
            "format": "###.##"
          }
        },
        "movavg": {
          "moving_avg": {
            "buckets_path": "avgTMax",
            "model": "holt",
            "window": 12,
            "gap_policy": "skip",
            "predict": 12,
            "settings": {
              "alpha": 0.8
            }
          }
        }
      }
    }
  }
}

Response snippet (the first three bucket are existing buckets, i.e. not predictions. The following 12 buckets are predictions but the bucket keys seem to start at 1986 and decrease by 20 years each time):

            {
               "key_as_string": "2005-07-01T00:00:00.000Z",
               "key": 1120176000000,
               "doc_count": 11,
               "avgTMax": {
                  "value": 28.8,
                  "value_as_string": "28.8"
               },
               "movavg": {
                  "value": 29.15195798473475
               }
            },
            {
               "key_as_string": "2005-10-01T00:00:00.000Z",
               "key": 1128124800000,
               "doc_count": 11,
               "avgTMax": {
                  "value": 29.172727272727272,
                  "value_as_string": "29.17"
               },
               "movavg": {
                  "value": 29.024912216300212
               }
            },
            {
               "key_as_string": "2006-01-01T00:00:00.000Z",
               "key": 1136073600000,
               "doc_count": 4,
               "avgTMax": {
                  "value": 29.525,
                  "value_as_string": "29.52"
               },
               "movavg": {
                  "value": 29.34023027099398
               }
            },
            {
               "key_as_string": "1986-01-01T00:00:00.000Z",
               "key": 504921600000,
               "doc_count": 0,
               "movavg": {
                  "value": 29.34023027099398,
                  "value_as_string": "1970-01-01T00:00:00.029Z"
               }
            },
            {
               "key_as_string": "1966-01-01T00:00:00.000Z",
               "key": -126230400000,
               "doc_count": 0,
               "movavg": {
                  "value": 29.28650429104976,
                  "value_as_string": "1970-01-01T00:00:00.029Z"
               }
            },
            {
               "key_as_string": "1946-01-01T00:00:00.000Z",
               "key": -757382400000,
               "doc_count": 0,
               "movavg": {
                  "value": 29.232778311105537,
                  "value_as_string": "1970-01-01T00:00:00.029Z"
               }
            },
            {
               "key_as_string": "1926-01-01T00:00:00.000Z",
               "key": -1388534400000,
               "doc_count": 0,
               "movavg": {
                  "value": 29.179052331161316,
                  "value_as_string": "1970-01-01T00:00:00.029Z"
               }
            },
            {
               "key_as_string": "1906-01-01T00:00:00.000Z",
               "key": -2019686400000,
               "doc_count": 0,
               "movavg": {
                  "value": 29.125326351217094,
                  "value_as_string": "1970-01-01T00:00:00.029Z"
               }
            },
            {
               "key_as_string": "1885-12-31T00:00:00.000Z",
               "key": -2650838400000,
               "doc_count": 0,
               "movavg": {
                  "value": 29.071600371272872,
                  "value_as_string": "1970-01-01T00:00:00.029Z"
               }
            },
            {
               "key_as_string": "1865-12-31T00:00:00.000Z",
               "key": -3281990400000,
               "doc_count": 0,
               "movavg": {
                  "value": 29.01787439132865,
                  "value_as_string": "1970-01-01T00:00:00.029Z"
               }
            },
            {
               "key_as_string": "1845-12-31T00:00:00.000Z",
               "key": -3913142400000,
               "doc_count": 0,
               "movavg": {
                  "value": 28.96414841138443,
                  "value_as_string": "1970-01-01T00:00:00.028Z"
               }
            },
            {
               "key_as_string": "1825-12-31T00:00:00.000Z",
               "key": -4544294400000,
               "doc_count": 0,
               "movavg": {
                  "value": 28.910422431440207,
                  "value_as_string": "1970-01-01T00:00:00.028Z"
               }
            },
            {
               "key_as_string": "1805-12-31T00:00:00.000Z",
               "key": -5175446400000,
               "doc_count": 0,
               "movavg": {
                  "value": 28.856696451495985,
                  "value_as_string": "1970-01-01T00:00:00.028Z"
               }
            },
            {
               "key_as_string": "1785-12-30T00:00:00.000Z",
               "key": -5806598400000,
               "doc_count": 0,
               "movavg": {
                  "value": 28.802970471551763,
                  "value_as_string": "1970-01-01T00:00:00.028Z"
               }
            },
            {
               "key_as_string": "1765-12-30T00:00:00.000Z",
               "key": -6437750400000,
               "doc_count": 0,
               "movavg": {
                  "value": 28.74924449160754,
                  "value_as_string": "1970-01-01T00:00:00.028Z"
               }
            }
@colings86
Copy link
Contributor Author

The problem is with [1], as this calculation of the interval does not work if key < 0 since the first bucket will calculate the interval as a negative value which will always be less than the actual interval. Also, I'm not sure this method works for non-fixed intervals like months, where the interval will change depending on what the key is

[1] https://github.com/elastic/elasticsearch/blob/35deb7efea9552528780082143db469afbcd3812/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgPipelineAggregator.java#L137-145

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant