Pagination on composite aggregation

Hi. I'm having such kind of problem on defining composite aggregation for paginating the results.

CompositeAggregationBuilder aggregationBuilder = AggregationBuilders
                    .composite(aggrField, List.of(new TermsValuesSourceBuilder(aggrField).field(aggrField)))
                    .aggregateAfter(Map.of("keyword", aggrField))

final SearchRequest searchRequest = new SearchRequest(bucketListInfo.getIndexName())
        try {
            final SearchResponse response =, RequestOptions.DEFAULT);
            return extractBucketsFromResponse1(bucketListInfo, response);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return null;

and this is the [extractBucketsFromResponse1] method definition.

    private static BucketList extractBucketsFromResponse1(final BucketListInfo bucketListInfo, final SearchResponse response) {
        final BucketList bucketList = new BucketList();
        for (String aggrField : bucketListInfo.getAggrFieldList()) {
            ParsedComposite terms = response.getAggregations().get(aggrField);
        return bucketList;

And when getting the results this way, the pagination doesn't work, it gives the wrong result.
Can anybody please help me on this issue.

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