# Terminate\_after with aggregation

**URL:** <https://discuss.elastic.co/t/terminate-after-with-aggregation/265179>\
**Category:** Elasticsearch\
**Created:** [February 23, 2021, 8:32am UTC](https://discuss.elastic.co/t/terminate-after-with-aggregation/265179 "2021-02-23T08:32:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dobkum](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dobkum/32/77755_2.png) [@dobkum](https://discuss.elastic.co/u/dobkum)\
**Post date:** [February 23, 2021, 8:32am UTC](https://discuss.elastic.co/t/terminate-after-with-aggregation/265179/1 "2021-02-23T08:32:52Z")

</div>

I want to know how aggregation behaves when combined with `terminate_after`.  
Is it that first the aggregations are performed from records belonging to all shards and then `terminate_after` setting are applied  
or  
first the records are collected based on `terminate_after` from each shard and then aggregation is applied.

Also, if it works the first way, then is it possible that lesser number of buckets are returned in the result than the actual number of buckets from all the shards

---

<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 23, 2021, 8:33am UTC](https://discuss.elastic.co/t/terminate-after-with-aggregation/265179/2 "2021-03-23T08:33:14Z")

</div>

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