# Pagination of sorted aggregation

**URL:** <https://discuss.elastic.co/t/pagination-of-sorted-aggregation/170890>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [March 5, 2019, 11:56am UTC](https://discuss.elastic.co/t/pagination-of-sorted-aggregation/170890 "2019-03-05T11:56:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TSaleem](https://avatars.discourse-cdn.com/v4/letter/t/6de8d8/32.png) [@TSaleem](https://discuss.elastic.co/u/TSaleem)\
**Post date:** [March 5, 2019, 11:56am UTC](https://discuss.elastic.co/t/pagination-of-sorted-aggregation/170890/1 "2019-03-05T11:56:51Z")

</div>

I am using packetbeat along with elasticsearch and i need to be able to paginate source.mac sorted according to bandwidth("source.stats.net\_bytes\_total" + "dest.stats.net\_bytes\_total").  
-Partition won't work because it only sorts within the given partition.  
-Collapse aggregation doesn't work because I need to have a scripted sort, which didn't give desired results.  
-Composite Aggregation failed because it only sorts the bucket key. I tried to make bandwidth as my bucket key but painless script only returns string values and not numbers, which ends up in string sort.  
Is there any other way? or should i just query all aggregation buckets and do pagination in my own code?

---

<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:** [April 2, 2019, 11:57am UTC](https://discuss.elastic.co/t/pagination-of-sorted-aggregation/170890/2 "2019-04-02T11:57:00Z")

</div>

Closed on April 2, 2019, 11:57am UTC

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