# Composite vs term aggregation with size

**URL:** <https://discuss.elastic.co/t/composite-vs-term-aggregation-with-size/165115>\
**Category:** Elasticsearch\
**Created:** [January 21, 2019, 8:01pm UTC](https://discuss.elastic.co/t/composite-vs-term-aggregation-with-size/165115 "2019-01-21T20:01:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vipul\_tyagi](https://avatars.discourse-cdn.com/v4/letter/v/c37758/32.png) [@vipul\_tyagi](https://discuss.elastic.co/u/vipul_tyagi)\
**Post date:** [January 21, 2019, 8:01pm UTC](https://discuss.elastic.co/t/composite-vs-term-aggregation-with-size/165115/1 "2019-01-21T20:01:20Z")

</div>

If I am using terms aggregation with size let's say 100000(knowing that there will not be more entry then it), should it return same result as using composite aggregation?

---

<div class="post-metadata">

**Author:** ![jimczi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jimczi/32/47985_2.png) [@jimczi](https://discuss.elastic.co/u/jimczi)\
**Post date:** [January 22, 2019, 7:54am UTC](https://discuss.elastic.co/t/composite-vs-term-aggregation-with-size/165115/2 "2019-01-22T07:54:18Z")

</div>

The `composite` aggregation should return the same terms but in a different order. The `terms` aggregation orders the terms by doc\_count by default whereas the composite uses the natural sort order (alphanumeric sort).

---

<div class="post-metadata">

**Author:** ![vipul\_tyagi](https://avatars.discourse-cdn.com/v4/letter/v/c37758/32.png) [@vipul\_tyagi](https://discuss.elastic.co/u/vipul_tyagi)\
**Post date:** [January 22, 2019, 8:11am UTC](https://discuss.elastic.co/t/composite-vs-term-aggregation-with-size/165115/3 "2019-01-22T08:11:57Z")

</div>

Thanks for a reply. I have doubt if term would result the entire set of data even if I know my cardinality. Let's say I defined size as 100000. Will it return the entire data.

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [January 22, 2019, 8:17am UTC](https://discuss.elastic.co/t/composite-vs-term-aggregation-with-size/165115/4 "2019-01-22T08:17:01Z")

</div>

Avoid packing too many buckets into one response.  
Look at making multiple requests using the “after” parameter in composite agg or the “partition” parameter in terms agg.

---

<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:** [February 19, 2019, 8:17am UTC](https://discuss.elastic.co/t/composite-vs-term-aggregation-with-size/165115/5 "2019-02-19T08:17:03Z")

</div>

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