5

I went through many articles to find any appropriate solution to add a Composite aggregation but did not find any relevant solution.

I have achieved it . See the answer, hope this will help.

Chirag Gupta
  • 115
  • 1
  • 7

2 Answers2

4

Here's the solution. Happy Coding ;)

List<CompositeValuesSourceBuilder<?>> sources = new ArrayList<>();

        sources.add(new TermsValuesSourceBuilder("aggregation_Name")
                                .field("field_Name"));
        sources.add(new TermsValuesSourceBuilder("aggregation_Name")
                .field("other_field"));
        CompositeAggregationBuilder compositeAggregationBuilder = new CompositeAggregationBuilder(
                "Composite_aggregation_Name", sources)
                        .size(10000);
Chirag Gupta
  • 115
  • 1
  • 7
0

SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();

        searchSourceBuilder
                .query(QueryBuilders.boolQuery()
                        .must(QueryBuilders
                                .queryStringQuery(filterPayload.getPayload().getModuleFilters().get(0).getValue()))
                        .must(QueryBuilders.termQuery("response.matching_rules_count", 1)))
                .aggregation(AggregationBuilders.terms("intent").field("request.qualificationData.intent.keyword")
                        .subAggregation(
                                AggregationBuilders.terms("rule").field("response.matchingRules.rule.ref.keyword"))
                        .subAggregation(AggregationBuilders.terms("statusCode").field("response.httpStatusCode"))
                        .size(1000000));

Here is the answer @user461127

Chirag Gupta
  • 115
  • 1
  • 7