1

我正在尝试查询一个弹性索引,其中查询的结果是只有一个匹配文档的 geohashes 列表。

我可以使用以下命令获取所有地理哈希及其文档计数的简单列表:

{ "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 } } } } } }

但是我无法找出正确的语法来过滤查询,我能得到的最接近的语法如下:

这失败了 503org.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" } } }

这失败了 400No 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" } } }

如何根据doc_countgeohash 网格中的 过滤?

4

1 回答 1

3

您需要这样做,即桶选择器管道应指定为该管道的子聚合geohash_grid。另外,您需要使用_count代替doc_count(请参见此处):

{
  "aggregations": {
    "grid": {
      "geohash_grid": {
        "field": "location",
        "precision": 4
      },
      "aggs": {
        "grid_bucket_filter": {
          "bucket_selector": {
            "buckets_path": {
              "docCount": "_count"
            },
            "script": "params.docCount > 1"
          }
        }
      }
    }
  }
}
于 2017-12-05T05:51:24.467 回答