【发布时间】:2016-06-26 14:22:42
【问题描述】:
我正在使用 Elasticsearch GeoHash 网格聚合进行地图聚类。 该查询平均返回 100-200 个桶。 每个存储桶都使用 top_hits 聚合,我使用它为每个聚合集群返回 3 个文档。
问题是我想仅在父聚合(GeoHash)聚合不超过 3 个文档时返回 top_hits。
如果一个集群聚合了超过 3 个文档,我不希望 ES 为这个集群返回任何文档(因为我不会使用它们)。
我尝试使用Bucket Selector Aggregation,但未能构建正确的bucket_path。
我在与 top_hits 聚合相同的级别上使用存储桶选择器聚合。
存储桶的总文档数可在 top_hits.hits.total 获得,但我得到的是 reason=path not supported for [top_hits]: [hits.total]。
这在弹性搜索中可能吗? 这对我来说很重要,因为在大多数查询中,只有一小部分存储桶的文档少于 3 个。但是即使对于 1000 个文档的集群,top hits 子聚合也总是返回前 3 个文档。 如果查询结果返回 200 个存储桶,其中只有 5 个在聚合
这是我查询的 aggs 部分:
"clusters": {
"geohash_grid": {
"field": "coordinates",
"precision": 3
},
"aggs": {
"top_hits": {
"top_hits": {
"size": 3
}
},
"top_hits_filter": {
"bucket_selector": {
"buckets_path": {
"total_hits": "top_hits._count" // tried top_hits.hits.total
},
"script": {
"inline": "total_hits <= 3"
}
}
}
}
}
【问题讨论】:
标签: elasticsearch elasticsearch-5 elasticsearch-aggregation