复合聚合在ElasticSearch Java中

huangapple go评论74阅读模式
英文:

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

这是解决方案。编码愉快 复合聚合在ElasticSearch Java中

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 复合聚合在ElasticSearch Java中

List&lt;CompositeValuesSourceBuilder&lt;?&gt;&gt; sources = new ArrayList&lt;&gt;();

        sources.add(new TermsValuesSourceBuilder(&quot;aggregation_Name&quot;)
                                .field(&quot;field_Name&quot;));
        sources.add(new TermsValuesSourceBuilder(&quot;aggregation_Name&quot;)
                .field(&quot;other_field&quot;));
        CompositeAggregationBuilder compositeAggregationBuilder = new CompositeAggregationBuilder(
                &quot;Composite_aggregation_Name&quot;, 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(&quot;response.matching_rules_count&quot;, 1)))
                .aggregation(AggregationBuilders.terms(&quot;intent&quot;).field(&quot;request.qualificationData.intent.keyword&quot;)
                        .subAggregation(
                                AggregationBuilders.terms(&quot;rule&quot;).field(&quot;response.matchingRules.rule.ref.keyword&quot;))
                        .subAggregation(AggregationBuilders.terms(&quot;statusCode&quot;).field(&quot;response.httpStatusCode&quot;))
                        .size(1000000));

Here is the answer @user461127

huangapple
  • 本文由 发表于 2020年4月9日 15:23:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/61115944.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定