Top Hits Aggregation support in Jest SearchResult

I am using below function to make aggregation query:

private TermsBuilder getAggregations(String[] outputFields) {

        TermsBuilder topLevelAggr = AggregationBuilders.terms("level1").field("field1").size(0);
        TermsBuilder aggr2 = AggregationBuilders.terms("level2").field("field2").size(0);
        TermsBuilder aggr3 = AggregationBuilders.terms("level3").field("field3").size(0);
        TermsBuilder aggr4 = AggregationBuilders.terms("level4").field("field4").size(0);
        TopHitsBuilder topHitsBuilder = AggregationBuilders.topHits("doc").setSize(1).addSort("fieldValue", SortOrder.DESC);

        topHitsBuilder.setFetchSource(outputFields, new String[]{});

        return topLevelAggr;

I am getting the correct aggregation query from this code, but after executing the query I am not able to extract the top_hits aggregation result. I am using io.searchbox.core.SearchResult class to get the query result. In this class I couldn't find any support for Top_Hits aggregation.

Please help. Thanks.

1 Like

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