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))
.size(bucketListInfo.getTopResultsCount());
searchSourceBuilder
.from(paginatedRequestInfo.from())
.size(paginatedRequestInfo.size())
.aggregation(aggregationBuilder);
final SearchRequest searchRequest = new SearchRequest(bucketListInfo.getIndexName())
.source(searchSourceBuilder);
try {
final SearchResponse response = restHighLevelClient.search(searchRequest, 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);
bucketList.getParsedBuckets().add(terms.getBuckets());
}
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.