# Why Aggregations moving\_avg dont compute first bucket data?

**URL:** <https://discuss.elastic.co/t/why-aggregations-moving-avg-dont-compute-first-bucket-data/43403>\
**Category:** Elasticsearch\
**Created:** [March 3, 2016, 2:54pm UTC](https://discuss.elastic.co/t/why-aggregations-moving-avg-dont-compute-first-bucket-data/43403 "2016-03-03T14:54:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gnepud](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gnepud/32/8243_2.png) [@gnepud](https://discuss.elastic.co/u/gnepud)\
**Post date:** [March 3, 2016, 2:54pm UTC](https://discuss.elastic.co/t/why-aggregations-moving-avg-dont-compute-first-bucket-data/43403/1 "2016-03-03T14:54:42Z")

</div>

Hi,

I want to get a last 12 month avg with aggregation moving avg like below example.  
Every values in month [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]  
I got a result by aggregation moving avg [null, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6]  
but i want to my result like [1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6, 6.5]

Version elasticsearch: 2.2  
search:  
`{ "query": { "match": { "indicator": { "query": "oee_steam", "type": "phrase" } } }, "aggs": { "last_12_months": { "date_histogram": { "field": "date", "interval": "1M", "format": "year_month", "time_zone": "+0100", "min_doc_count": 0 }, "aggs": { "month_avg": { "avg": { "field": "value" } }, "the_movavg": { "moving_avg": { "buckets_path": "month_avg", "window": 12 } } } } } }`  
resulat:  
`{ "took": 6, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 427, "max_score": 0, "hits": [] }, "aggregations": { "last_12_months": { "buckets": [{ "key_as_string": "2015-01", "key": 1420066800000, "doc_count": 31, "month_avg": { "value": 1.0036290249516886 } }, { "key_as_string": "2015-02", "key": 1422745200000, "doc_count": 28, "month_avg": { "value": 0.9984788341181619 }, "the_movavg": { "value": 1.0036290249516886 } }, { "key_as_string": "2015-03", "key": 1425164400000, "doc_count": 32, "month_avg": { "value": 0.9724848084151745 }, "the_movavg": { "value": 1.0010539295349252 } }, { "key_as_string": "2015-04", "key": 1427842800000, "doc_count": 30, "month_avg": { "value": 1.0054521600405375 }, "the_movavg": { "value": 0.991530889161675 } }] } } }`

I havnt the\_movavg value for my first buckets value.

The question is why aggregation moving avg dont compute first value but begin always second value ?  
And How to get a result like i wanted ?

Thanks and sorry my English is poor.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 11:11pm UTC](https://discuss.elastic.co/t/why-aggregations-moving-avg-dont-compute-first-bucket-data/43403/2 "2017-07-05T23:11:35Z")

</div>


