我正在尝试查询一个 flex 索引,其中查询结果是仅具有一个匹配文档的地质哈希列表。
我可以使用以下方法获得所有地理哈希值及其文档计数的简单列表:{ "size" : 0, "aggregations" : { "boundingbox" : { "filter" : { "geo_bounding_box" : { "location" : { "top_left" : "34.5, -118.9", "bottom_right" : "33.3, -116." } } }, "aggregations":{ "grid" : { "geohash_grid" : { "field": "location", "precision": 4 } } } } }}
但是我无法计算出正确的语法来过滤查询,下面是我能得到的最接近的语法:
这失败,显示503 org.elasticsearch.search.aggregations.bucket.filter.InternalFilter cannot be cast to org.elasticsearch.search.aggregations.InternalMultiBucketAggregation
"aggregations":{ "grid" : { "geohash_grid" : { "field": "location", "precision": 4 } }, "grid_bucket_filter" : { "bucket_selector" : { "buckets_path" :{ "docCount" : "grid" //Also tried `"docCount" : "doc_count"` }, "script" : "params.docCount == 1" } }}
这失败,显示400 No aggregation found for path [doc_count]
"aggregations":{ "grid" : { "geohash_grid" : { "field": "location", "precision": 4 } }, "grid_bucket_filter" : { "bucket_selector" : { "buckets_path" :{ "docCount" : "doc_count" }, "script" : "params.docCount > 1" } }}
如何在geohash网格中基于doc_count
进行过滤?
最佳答案
您需要这样做,也就是说,将桶选择器管道指定为geohash_grid
one的子集合。另外,您需要使用_count
而不是doc_count
(请参阅here):
{
"aggregations": {
"grid": {
"geohash_grid": {
"field": "location",
"precision": 4
},
"aggs": {
"grid_bucket_filter": {
"bucket_selector": {
"buckets_path": {
"docCount": "_count"
},
"script": "params.docCount > 1"
}
}
}
}
}
}
关于elasticsearch - Elastic GeoHash查询-聚合过滤器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47591522/