1

我的弹性搜索中有以下映射:

{
  "mappings": {
    "event": {
      "_all":       { "enabled": false  },
      "properties": {
        "type":     { "type": "string", "index": "not_analyzed"},
        "id":  { "type": "string"},
        "location": { "type": "geo_point"}
      }
    }
  }
} 

我想要做的是查询由单个 geohash 定义的地图区域内本地化的所有记录。我知道 geohash 单元格查询在我的示例中可以完美运行,但不幸的是,geohash_prefix 选项设置为 true 时需要对 geo_point 字段进行索引,这在 elasticearch 2.4 中已弃用。

在最新的弹性搜索版本中正确的方法是什么?我在文档中的任何地方都找不到它。

4

2 回答 2

1

Elasticsearch 6.0.0-alpha2文档说明如下:

geohash_cell 查询已被删除。而是使用地理边界框查询

尝试将bottom_left 边界框参数指定为 asyour_geohash_prefix + '00...0'top_rightas your_geohash_prefix + 'zz...z'。您应该将尽可能多的0z符号附加到您的 geohash 前缀,使其长度为 12(最大精度 geohash 长度)。

例如对于 geohash 前缀dr5r9,它看起来像:

{
    "query": {
        "bool" : {
            "must" : {
                "match_all" : {}
            },
            "filter" : {
                "geo_bounding_box" : {
                    "coordinates" : {
                        "bottom_left" : "dr5r90000000",
                        "top_right" : "dr5r9zzzzzzz"
                    }
                }
            }
        }
    }
}

0z分别作为 geohash 网格的左下角和右上角。

通过将匹配的文档计数与相应精度的 geohash 网格聚合结果进行比较,我成功地使用了这种方法对其进行了测试。但是我仍然有一些情况,有些点没有落入这样的边界框。不能说它是 100% 正确的方法。

于 2017-06-22T15:52:56.930 回答
0

要获得所有分数,请尝试添加0z在 Sergii 的答案中,但要解码并使用 geo_bounding_box 查询与顶部、左侧、底部、右侧。

dr5r90000000 -> 经度:-74.13574202,纬度:40.69335946

dr5r90zzzzzz -> 经度:-74.12475603,纬度:40.69885246

{
    "query": {
        "bool" : {
            "must" : {
                "match_all" : {}
            },
            "filter" : {
                "geo_bounding_box" : {
                    "coordinates" : {
                        "top": 40.69885246,
                        "left": -74.13574202,
                        "bottom": 40.69335946,
                        "right": -74.12475603,
                    }
                }
            }
        }
    }
}
于 2019-12-21T14:57:01.800 回答