[英]Elasticsearch Subaggregation of tophits JAVA API not working
我想在 JAVA API 中编写 elasticsearch 聚合来查找字段折叠和结果分组。
json 聚合代码如下所示我从elasticsearch 文档中获得了这些代码
“dedup_by_score”聚合具有称为“top_hit”聚合的子聚合,并将其用于存储桶排序的聚合。
... some query
"aggs": {
"dedup_by_score": {
"terms": {
"field": "keyword",
"order": {
"top_hit": "desc"
},
"size": 10
},
"aggs": {
"top_hit": {
"max": {
"script": {
"source": "_score"
}
}
}
}
}
}
我想将此 json 查询转换为 JAVA
这就是我已经在 JAVA 中尝试过的
AggregationBuilder aggregation = AggregationBuilders.terms("dedup_by_score")
.field("keyword")
.order(BucketOrder.aggregation("top_hit", false))
.size(10)
.subAggregation(
AggregationBuilders.topHits("top_hit")
.subAggregation(
AggregationBuilders.max("max").script(new Script("_score"))
)
);
但是我从 Elasticsearch 收到了如下所示的错误
{
"type":"aggregation_initialization_exception",
"reason":"Aggregator [top_hit] of type [top_hits] cannot accept sub-aggregations"
}
如何修复此 Java 代码? 我现在使用的是 Elasticsearch 6.7.1 版本。
提前致谢
热门 aggs 不能有 sub-aggs。 尝试这个:
AggregationBuilder aggregation = AggregationBuilders.terms("dedup_by_score")
.field("keyword")
.order(BucketOrder.aggregation("top_hit", false))
.size(10)
.subAggregation(
AggregationBuilders.max("max").script(new Script("_score"))
.subAggregation(
AggregationBuilders.topHits("top_hit")
)
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.