# How to implement pagination in composite aggregation after removing some buckets based on condition by BucketSelectorAggregation

**URL:** <https://discuss.elastic.co/t/how-to-implement-pagination-in-composite-aggregation-after-removing-some-buckets-based-on-condition-by-bucketselectoraggregation/280168>\
**Category:** Elasticsearch\
**Created:** [August 2, 2021, 1:27am UTC](https://discuss.elastic.co/t/how-to-implement-pagination-in-composite-aggregation-after-removing-some-buckets-based-on-condition-by-bucketselectoraggregation/280168 "2021-08-02T01:27:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dipuoec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dipuoec/32/92423_2.png) [@dipuoec](https://discuss.elastic.co/u/dipuoec)\
**Post date:** [August 2, 2021, 1:27am UTC](https://discuss.elastic.co/t/how-to-implement-pagination-in-composite-aggregation-after-removing-some-buckets-based-on-condition-by-bucketselectoraggregation/280168/1 "2021-08-02T01:27:26Z")

</div>

I am trying to implement the inbuilt pagination feature available in Elasticsearch composite aggregation on aggregated data. This works perfectly fine until we are not removing certain buckets based on conditions of aggregated fields. To remove buckets I am using BucketSelectorAggregation.

I understand that composite aggregation doesn't support pipeline aggregation fully and the reason for the issue is after\_key and size always consider the aggregation response for pagination, rather than filtred aggregated data.

If anybody can help on this to apply the pagination on the aggregated filtered bucket using some kind of filter or other option without using pipeline aggregation that would be great.

Example :

## id sum

1 100  
2 200  
3 400  
4 500  
5 100

Query after aggregation to get 2 records

**Result**

## id sum

1 100  
2 200

Query after aggregation and BucketSelectorAggregation to get 2 records where sum value 100

## **Result**

1 100

## **Expected Result**

1 100  
5 100

---

<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:** [August 30, 2021, 1:28am UTC](https://discuss.elastic.co/t/how-to-implement-pagination-in-composite-aggregation-after-removing-some-buckets-based-on-condition-by-bucketselectoraggregation/280168/2 "2021-08-30T01:28:19Z")

</div>

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