# Maximum number of documents considered for aggregation

**URL:** <https://discuss.elastic.co/t/maximum-number-of-documents-considered-for-aggregation/62314>\
**Category:** Elasticsearch\
**Created:** [October 5, 2016, 9:21pm UTC](https://discuss.elastic.co/t/maximum-number-of-documents-considered-for-aggregation/62314 "2016-10-05T21:21:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![blimpse](https://avatars.discourse-cdn.com/v4/letter/b/5e9695/32.png) [@blimpse](https://discuss.elastic.co/u/blimpse)\
**Post date:** [October 5, 2016, 9:21pm UTC](https://discuss.elastic.co/t/maximum-number-of-documents-considered-for-aggregation/62314/1 "2016-10-05T21:21:24Z")

</div>

I know that the number of results is limited by the "size" parameter, but is there a maximum number of documents that elasticsearch "looks through" when performing an aggregation query? I want to make sure that the totals reported in my aggregations are going to be accurate as the sizes of my indexes increase.

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [October 5, 2016, 9:35pm UTC](https://discuss.elastic.co/t/maximum-number-of-documents-considered-for-aggregation/62314/2 "2016-10-05T21:35:49Z")

</div>

They'll be accurate. You can use `terminate_after` to make them _not_ accurate if you want.

The `size` and `offset` parameters control the number of documents returned in the fetch phase. The `terminate_after` parameter controls the number of documents collected by the query phase. Aggregations are a part of the query phase.

---

<div class="post-metadata">

**Author:** ![blimpse](https://avatars.discourse-cdn.com/v4/letter/b/5e9695/32.png) [@blimpse](https://discuss.elastic.co/u/blimpse)\
**Post date:** [October 5, 2016, 10:13pm UTC](https://discuss.elastic.co/t/maximum-number-of-documents-considered-for-aggregation/62314/3 "2016-10-05T22:13:20Z")

</div>

Great! Thank you.

---

<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, 10:14pm UTC](https://discuss.elastic.co/t/maximum-number-of-documents-considered-for-aggregation/62314/4 "2017-07-05T22:14:35Z")

</div>


