# Aggregation score and decay

**URL:** <https://discuss.elastic.co/t/aggregation-score-and-decay/37271>\
**Category:** Elasticsearch\
**Created:** [December 15, 2015, 7:03pm UTC](https://discuss.elastic.co/t/aggregation-score-and-decay/37271 "2015-12-15T19:03:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevins](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kevins/32/946_2.png) [@kevins](https://discuss.elastic.co/u/kevins)\
**Post date:** [December 15, 2015, 7:03pm UTC](https://discuss.elastic.co/t/aggregation-score-and-decay/37271/1 "2015-12-15T19:03:50Z")

</div>

When calculating an average for a field in the documents using an aggregation we typically create a date range filter. I am curious to know if it is possible to construct an aggregation using a custom score with a decay.

e.g. give me the average and use the data from:  
now to now-1w (score 1) +  
now-1w to now-2w (score 0.5 w decay) +  
etc.

Is this possible? I use a method now that simply does multiple queries and builds my own weighted average and would prefer a better method.

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [December 16, 2015, 12:07pm UTC](https://discuss.elastic.co/t/aggregation-score-and-decay/37271/2 "2015-12-16T12:07:55Z")

</div>

If I understand what you are trying to do correctly, I think you might be looking for the moving average pipeline aggregation which was released in 2.0: [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-movavg-aggregation.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-movavg-aggregation.html)

Hope that helps

---

<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:30pm UTC](https://discuss.elastic.co/t/aggregation-score-and-decay/37271/3 "2017-07-05T23:30:37Z")

</div>

Closed on July 5, 2017, 11:30pm UTC


