# Perform aggregation on small set of documents

**URL:** <https://discuss.elastic.co/t/perform-aggregation-on-small-set-of-documents/264515>\
**Category:** Elasticsearch\
**Created:** [February 17, 2021, 7:07am UTC](https://discuss.elastic.co/t/perform-aggregation-on-small-set-of-documents/264515 "2021-02-17T07:07:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Madhu\_Dasa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/madhu_dasa/32/84014_2.png) [@Madhu\_Dasa](https://discuss.elastic.co/u/Madhu_Dasa)\
**Post date:** [February 17, 2021, 7:07am UTC](https://discuss.elastic.co/t/perform-aggregation-on-small-set-of-documents/264515/1 "2021-02-17T07:07:57Z")

</div>

I have a query which returns 100 documents. While performing aggregation it considers all the documents . But I want to apply aggregation only on top 5 documents. Is there a way to achieve this?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [February 17, 2021, 7:40am UTC](https://discuss.elastic.co/t/perform-aggregation-on-small-set-of-documents/264515/2 "2021-02-17T07:40:33Z")

</div>

Welcome to our community! 😃

How do you determine the top 5?

---

<div class="post-metadata">

**Author:** ![Madhu\_Dasa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/madhu_dasa/32/84014_2.png) [@Madhu\_Dasa](https://discuss.elastic.co/u/Madhu_Dasa)\
**Post date:** [February 17, 2021, 9:55am UTC](https://discuss.elastic.co/t/perform-aggregation-on-small-set-of-documents/264515/3 "2021-02-17T09:55:50Z")

</div>

We have sorted based on geodistance.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [February 21, 2021, 9:26pm UTC](https://discuss.elastic.co/t/perform-aggregation-on-small-set-of-documents/264515/4 "2021-02-21T21:26:50Z")

</div>

Ok, so if you have a sort for that then you can change the size to 5.

---

<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:** [March 21, 2021, 9:27pm UTC](https://discuss.elastic.co/t/perform-aggregation-on-small-set-of-documents/264515/5 "2021-03-21T21:27:41Z")

</div>

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