给定lat / lng,找到lat / lng所在的每个圆

时间:2016-11-24 08:41:05

标签: elasticsearch elasticsearch-geo-shape

我有一个列表geoshape文件,如下所示:

{
    "location" : {
        "type" : "circle",
        "coordinates" : [-45.0, 45.0],
        "radius" : "8000m"
    }
 }

给定一个lat / lng,我想找到这个lat / lng所在的所有文件。

1 个答案:

答案 0 :(得分:2)

您需要使用geo_shape这样的查询:

{
  "query": {
    "bool": {
      "filter": {
        "geo_shape": {
          "location": {
            "shape": {
              "type": "point",
              "coordinates": [ -77.03653, 38.897676 ]   <-- lon/lat to search
            },
            "relation": "contains"                      <-- use the contains relationship
          }
        }
      }
    }
  }
}

coordinates参数中,确保在纬度之前设置经度,而不是相反(感谢GeoJSON)