# Using aggr query over a specific size of result instead of entire index

**URL:** <https://discuss.elastic.co/t/using-aggr-query-over-a-specific-size-of-result-instead-of-entire-index/93087>\
**Category:** Elasticsearch\
**Created:** [July 13, 2017, 11:10pm UTC](https://discuss.elastic.co/t/using-aggr-query-over-a-specific-size-of-result-instead-of-entire-index/93087 "2017-07-13T23:10:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nidhi\_Thakkar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nidhi_thakkar/32/20054_2.png) [@Nidhi\_Thakkar](https://discuss.elastic.co/u/Nidhi_Thakkar)\
**Post date:** [July 13, 2017, 11:10pm UTC](https://discuss.elastic.co/t/using-aggr-query-over-a-specific-size-of-result-instead-of-entire-index/93087/1 "2017-07-13T23:10:24Z")

</div>

I am fairly new to Elasticsearch.  
I want to find the avg of only the most recent 50 results instead of my entire index. Is there any way I can do it?  
I cannot find a query with which I can aggr over specific size and ordering of result.

---

<div class="post-metadata">

**Author:** ![Rory](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@Rory](https://discuss.elastic.co/u/Rory)\
**Post date:** [July 14, 2017, 1:15pm UTC](https://discuss.elastic.co/t/using-aggr-query-over-a-specific-size-of-result-instead-of-entire-index/93087/2 "2017-07-14T13:15:59Z")

</div>

I think you'll have to try to do this in 2 steps. The initial query gets you the top 50 documents (along with the attribute in the document which you want to aggregate) based on some timestamp attribute. And then you can perform a quick average operation(doesn't have to be a part of ES you can use any programming language to do this) on the values returned by the first query.

---

<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:** [August 11, 2017, 1:16pm UTC](https://discuss.elastic.co/t/using-aggr-query-over-a-specific-size-of-result-instead-of-entire-index/93087/3 "2017-08-11T13:16:27Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
