使用 Java 的 ElasticSearch 聚合

萨金·苏伦德兰

我有一个弹性查询

{
  "size": 0,
  "aggs": {
    "group_by_cluster": {
      "terms": {
        "field": "cluster"
      }
    }
  }
}

http://localhost:9200/index/type/_search

与邮递员一起尝试时,我得到了结果。现在正在尝试编写相应的java代码。(ElasticSearch 5.5 版)

SearchQuery searchQuery = new NativeSearchQueryBuilder()
.withIndices("index")
.withTypes("type")
.addAggregation(AggregationBuilders
.global("agg")          
.subAggregation(AggregationBuilders.terms("group_by_cluster").field("cluster")))
.build();
 Aggregations aggregations = elasticTemplate.query(searchQuery, new 
 ResultsExtractor<Aggregations>() {
 @Override
 public Aggregations extract(SearchResponse response) {
 return response.getAggregations();
 }
 } );

但结果是空的。请帮我解决这个问题

萨金·苏伦德兰

这是我的错误。类型区分大小写,我在原始代码中使用了驼峰命名法。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章