Reputation: 115
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.
Upvotes: 5
Views: 3359
Reputation: 115
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
Upvotes: 0
Reputation: 115
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);
Upvotes: 4