{"action":"created","issue":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/10024","labels_url":"https://api.github.com/repos/elastic/elasticsearch/issues/10024/labels{/name}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/10024/comments","events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/10024/events","html_url":"https://github.com/elastic/elasticsearch/pull/10024","id":60167636,"number":10024,"title":"Aggregations: Add moving average aggregation","user":{"login":"polyfractal","id":1224228,"avatar_url":"https://avatars.githubusercontent.com/u/1224228?v=3","gravatar_id":"","url":"https://api.github.com/users/polyfractal","html_url":"https://github.com/polyfractal","followers_url":"https://api.github.com/users/polyfractal/followers","following_url":"https://api.github.com/users/polyfractal/following{/other_user}","gists_url":"https://api.github.com/users/polyfractal/gists{/gist_id}","starred_url":"https://api.github.com/users/polyfractal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/polyfractal/subscriptions","organizations_url":"https://api.github.com/users/polyfractal/orgs","repos_url":"https://api.github.com/users/polyfractal/repos","events_url":"https://api.github.com/users/polyfractal/events{/privacy}","received_events_url":"https://api.github.com/users/polyfractal/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/elastic/elasticsearch/labels/:Aggs","name":":Aggs","color":"009800"},{"url":"https://api.github.com/repos/elastic/elasticsearch/labels/feature","name":"feature","color":"328a58"},{"url":"https://api.github.com/repos/elastic/elasticsearch/labels/review","name":"review","color":"0052cc"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-03-06T22:23:37Z","updated_at":"2015-03-18T15:10:19Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/10024","html_url":"https://github.com/elastic/elasticsearch/pull/10024","diff_url":"https://github.com/elastic/elasticsearch/pull/10024.diff","patch_url":"https://github.com/elastic/elasticsearch/pull/10024.patch"},"body":"Adds an aggregation to calculate the moving average of sibling metrics in histogram-style data (histogram, date_histogram). Moving averages are useful when time series data is locally stationary and has a mean that changes slowly over time.\r\n\r\nSeasonal data may need a different analysis, as well as data that is bimodal, \"bursty\" or contains frequent extreme values (which are not necessarily outliers).\r\n\r\n#### Request\r\n\r\n```json\r\nGET /test/_search?search_type=count\r\n{\r\n   \"aggs\": {\r\n      \"my_date_histo\": {\r\n         \"date_histogram\": {\r\n            \"field\": \"@timestamp\",\r\n            \"interval\": \"day\"\r\n         },\r\n         \"aggs\": {\r\n            \"the_sum\": {\r\n               \"sum\": {\r\n                  \"field\": \"price\"\r\n               }\r\n            },\r\n            \"the_movavg\": {\r\n               \"movavg\": {\r\n                  \"bucketsPath\": \"the_sum\",\r\n                  \"window\": 3,\r\n                  \"weighting\" : \"single_exp\",\r\n                  \"gap_policy\" : \"ignore\",\r\n                  \"settings\" : {\r\n                    \"alpha\" : 0.5\r\n                  }\r\n               }\r\n            }\r\n         }\r\n      }\r\n   }\r\n}\r\n```\r\n\r\n##### `bucketsPath` (Required)\r\nPath to buckets/metric values to calculate moving average over\r\n\r\n##### `window` (Optional - default 5)\r\nThe user specifies the window size they wish to calculate a moving average for. E.g. a user may want a 30-day sliding window over a histogram of 90 days total.\r\n\r\nCurrently, if there is not enough data to \"fill\" the window, the moving average will be calculated with whatever is available. For example, if a user selects 30-day window, days 1-29 will calculate the moving average with between 1-29 days of data.\r\n\r\nWe could investigate adding more \"edge policies\", which determine how to handle gaps at the edge of the moving average\r\n\r\n##### `weighting` (Optional - default `simple`)\r\n\r\nCurrently, the agg supports four types of weighting:\r\n\r\n- simple: A simple (arithmetic) average. Default.\r\n- linear: A linearly weighted average, such that data becomes linearly less important as it gets \"older\" in the window\r\n- single_exp: Single exponentially weighted average (aka EWMA or Brown's Simple Exp Smoothing), such that data becomes exponentially less important as it get's \"older\".\r\n- double_exp: Double exponentially weighted average (aka Holt-Winters). Uses two exponential terms: first smooth data exponentially like single_exp, but then apply second corrective smoothing to account for a trend.\r\n\r\n##### `gap_policy` (Optional - default `ignore`)\r\nDetermines the policy for handling gaps in the data.  Default is to ignore gaps.\r\n\r\n##### `settings` (Optional)\r\nExtra settings which apply to individual weighting types.  \r\n\r\n- `alpha` can be set for `single_exp`. Defaults to 0.5\r\n- `alpha` and `beta` can be set for `double_exp`.  Defaults to 0.5 and 0.5 respectively.\r\n\r\n#### Response\r\n\r\n```json\r\n{\r\n   \"took\": 3,\r\n   \"timed_out\": false,\r\n   \"aggregations\": {\r\n      \"my_date_histo\": {\r\n         \"buckets\": [\r\n            {\r\n               \"key_as_string\": \"2014-12-01T00:00:00.000Z\",\r\n               \"key\": 1417392000000,\r\n               \"doc_count\": 1,\r\n               \"the_sum\": {\r\n                  \"value\": 1,\r\n                  \"value_as_string\": \"1.0\"\r\n               },\r\n               \"the_movavg\": {\r\n                  \"value\": 1\r\n               }\r\n            },\r\n            {\r\n               \"key_as_string\": \"2014-12-02T00:00:00.000Z\",\r\n               \"key\": 1417478400000,\r\n               \"doc_count\": 1,\r\n               \"the_sum\": {\r\n                  \"value\": 2,\r\n                  \"value_as_string\": \"2.0\"\r\n               },\r\n               \"the_movavg\": {\r\n                  \"value\": 1.5\r\n               }\r\n            },\r\n            {\r\n               \"key_as_string\": \"2014-12-04T00:00:00.000Z\",\r\n               \"key\": 1417651200000,\r\n               \"doc_count\": 1,\r\n               \"the_sum\": {\r\n                  \"value\": 4,\r\n                  \"value_as_string\": \"4.0\"\r\n               },\r\n               \"the_movavg\": {\r\n                  \"value\": 2.3333333333333335\r\n               }\r\n            },\r\n            {\r\n               \"key_as_string\": \"2014-12-05T00:00:00.000Z\",\r\n               \"key\": 1417737600000,\r\n               \"doc_count\": 1,\r\n               \"the_sum\": {\r\n                  \"value\": 5,\r\n                  \"value_as_string\": \"5.0\"\r\n               },\r\n               \"the_movavg\": {\r\n                  \"value\": 3.6666666666666665\r\n               }\r\n            },\r\n            {\r\n               \"key_as_string\": \"2014-12-08T00:00:00.000Z\",\r\n               \"key\": 1417996800000,\r\n               \"doc_count\": 1,\r\n               \"the_sum\": {\r\n                  \"value\": 8,\r\n                  \"value_as_string\": \"8.0\"\r\n               },\r\n               \"the_movavg\": {\r\n                  \"value\": 5.666666666666667\r\n               }\r\n            },\r\n            {\r\n               \"key_as_string\": \"2014-12-09T00:00:00.000Z\",\r\n               \"key\": 1418083200000,\r\n               \"doc_count\": 1,\r\n               \"the_sum\": {\r\n                  \"value\": 9,\r\n                  \"value_as_string\": \"9.0\"\r\n               },\r\n               \"the_movavg\": {\r\n                  \"value\": 7.333333333333333\r\n               }\r\n            }\r\n         ]\r\n      }\r\n   }\r\n}\r\n```\r\n\r\nCloses #10002"},"comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/comments/83016777","html_url":"https://github.com/elastic/elasticsearch/pull/10024#issuecomment-83016777","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/10024","id":83016777,"user":{"login":"polyfractal","id":1224228,"avatar_url":"https://avatars.githubusercontent.com/u/1224228?v=3","gravatar_id":"","url":"https://api.github.com/users/polyfractal","html_url":"https://github.com/polyfractal","followers_url":"https://api.github.com/users/polyfractal/followers","following_url":"https://api.github.com/users/polyfractal/following{/other_user}","gists_url":"https://api.github.com/users/polyfractal/gists{/gist_id}","starred_url":"https://api.github.com/users/polyfractal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/polyfractal/subscriptions","organizations_url":"https://api.github.com/users/polyfractal/orgs","repos_url":"https://api.github.com/users/polyfractal/repos","events_url":"https://api.github.com/users/polyfractal/events{/privacy}","received_events_url":"https://api.github.com/users/polyfractal/received_events","type":"User","site_admin":false},"created_at":"2015-03-18T15:10:19Z","updated_at":"2015-03-18T15:10:19Z","body":"Awesome, thanks @colings86, all seemed reasonable but had question about the Weighting builder stuff.  I'll fixup the other stuff right now."}}