复合聚合在ElasticSearch Java中

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

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中

  1. List<CompositeValuesSourceBuilder<?>> sources = new ArrayList<>();
  2. sources.add(new TermsValuesSourceBuilder("aggregation_Name")
  3. .field("field_Name"));
  4. sources.add(new TermsValuesSourceBuilder("aggregation_Name")
  5. .field("other_field"));
  6. CompositeAggregationBuilder compositeAggregationBuilder = new CompositeAggregationBuilder(
  7. "Composite_aggregation_Name", sources)
  8. .size(10000);
英文:

Here's the solution. Happy Coding 复合聚合在ElasticSearch Java中

  1. List&lt;CompositeValuesSourceBuilder&lt;?&gt;&gt; sources = new ArrayList&lt;&gt;();
  2. sources.add(new TermsValuesSourceBuilder(&quot;aggregation_Name&quot;)
  3. .field(&quot;field_Name&quot;));
  4. sources.add(new TermsValuesSourceBuilder(&quot;aggregation_Name&quot;)
  5. .field(&quot;other_field&quot;));
  6. CompositeAggregationBuilder compositeAggregationBuilder = new CompositeAggregationBuilder(
  7. &quot;Composite_aggregation_Name&quot;, sources)
  8. .size(10000);

答案2

得分: 0

  1. SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
  2. searchSourceBuilder
  3. .query(QueryBuilders.boolQuery()
  4. .must(QueryBuilders
  5. .queryStringQuery(filterPayload.getPayload().getModuleFilters().get(0).getValue()))
  6. .must(QueryBuilders.termQuery("response.matching_rules_count", 1)))
  7. .aggregation(AggregationBuilders.terms("intent").field("request.qualificationData.intent.keyword")
  8. .subAggregation(
  9. AggregationBuilders.terms("rule").field("response.matchingRules.rule.ref.keyword"))
  10. .subAggregation(AggregationBuilders.terms("statusCode").field("response.httpStatusCode"))
  11. .size(1000000));
英文:

SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();

  1. searchSourceBuilder
  2. .query(QueryBuilders.boolQuery()
  3. .must(QueryBuilders
  4. .queryStringQuery(filterPayload.getPayload().getModuleFilters().get(0).getValue()))
  5. .must(QueryBuilders.termQuery(&quot;response.matching_rules_count&quot;, 1)))
  6. .aggregation(AggregationBuilders.terms(&quot;intent&quot;).field(&quot;request.qualificationData.intent.keyword&quot;)
  7. .subAggregation(
  8. AggregationBuilders.terms(&quot;rule&quot;).field(&quot;response.matchingRules.rule.ref.keyword&quot;))
  9. .subAggregation(AggregationBuilders.terms(&quot;statusCode&quot;).field(&quot;response.httpStatusCode&quot;))
  10. .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:

确定