英文:
Composite Aggregation in ElasticSearch Java
问题
我查看了许多文章,寻找任何适当的解决方案来添加一个Composite聚合,但没有找到任何相关的解决方案。
我已经实现了它。请查看答案,希望这会有所帮助。
英文:
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.
答案1
得分: 4
这是解决方案。编码愉快
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);
英文:
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);
答案2
得分: 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));
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论