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.

2 Answers 2

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);
Sign up to request clarification or add additional context in comments.

3 Comments

Any idea how to achieve composite aggregation and subaggregation as a composite aggregation as well?
@user461127 Posting an answer for you. May be it helps
Can u help me through this? stackoverflow.com/questions/78373328/…
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.