# Aggregation Pagination Composite VS Include Partion

**URL:** <https://discuss.elastic.co/t/aggregation-pagination-composite-vs-include-partion/160700>\
**Category:** Elasticsearch\
**Created:** [December 13, 2018, 9:49am UTC](https://discuss.elastic.co/t/aggregation-pagination-composite-vs-include-partion/160700 "2018-12-13T09:49:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gary\_Harpaz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gary_harpaz/32/38779_2.png) [@Gary\_Harpaz](https://discuss.elastic.co/u/Gary_Harpaz)\
**Post date:** [December 13, 2018, 9:49am UTC](https://discuss.elastic.co/t/aggregation-pagination-composite-vs-include-partion/160700/1 "2018-12-13T09:49:42Z")

</div>

Hi,

At my company we use a terms aggregation with include: partition number to paginate the results.  
I noticed that in newer versions you have a composite aggregation which also allows pagination.  
Which do you think is a better solution?  
Is there a performance difference between the methods?

Thanks,

Gary

---

<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:** [December 13, 2018, 11:06am UTC](https://discuss.elastic.co/t/aggregation-pagination-composite-vs-include-partion/160700/2 "2018-12-13T11:06:51Z")

</div>

Composite aggregation is reliant on ordering buckets by a key that is derived from values in a single document. Taking a simple example, ordering buckets by IPAddress or perhaps extracting the domain name from a `referrerUrl` field. Each of these buckets can have sub aggregations e.g. max of `date` field (to know the last time you saw them) but you can't order the top-level buckets on this child agg "max date" property which is derived from multiple docs.

The `terms` aggregation can order by the values of child-aggregations e.g. reverse-sort on the max `date` value for an IP address to find IP addresses that haven't been active in a while. The downside is if the number of unique top-level buckets (IP addresses in this case ) is large you may have to use partitioning to ensure results are accurate within each arbitrary subset of the data.

---

<div class="post-metadata">

**Author:** ![Gary\_Harpaz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gary_harpaz/32/38779_2.png) [@Gary\_Harpaz](https://discuss.elastic.co/u/Gary_Harpaz)\
**Post date:** [December 13, 2018, 12:16pm UTC](https://discuss.elastic.co/t/aggregation-pagination-composite-vs-include-partion/160700/3 "2018-12-13T12:16:14Z")

</div>

I am referring to the ability to paginate a composite aggregation with a single source terms aggregation using after:  
If the number of composite buckets is too high (or unknown) to be returned in a single response it is possible to split the retrieval in multiple requests  
See:  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-composite-aggregation.html#\_after](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-composite-aggregation.html#_after)

---

<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:** [December 13, 2018, 12:25pm UTC](https://discuss.elastic.co/t/aggregation-pagination-composite-vs-include-partion/160700/4 "2018-12-13T12:25:24Z")

</div>

> [@Gary\_Harpaz](#):
>
> I am referring to the ability to paginate a composite aggregation with a single source terms aggregation using after

Ah OK - so you've no need for ordering by child aggs etc. I'd expect Composite to be faster for this use case then.

---

<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:** [January 10, 2019, 12:25pm UTC](https://discuss.elastic.co/t/aggregation-pagination-composite-vs-include-partion/160700/5 "2019-01-10T12:25:25Z")

</div>

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