查找多边形中的坐标

bpsygsoo  于 2021-06-13  发布在  ElasticSearch
关注(0)|答案(1)|浏览(339)

如何找到存储在弹性索引中的多边形。简单Map:

PUT /regions
{
    "mappings": {
        "properties": {
            "location": {
                "type": "geo_shape"
            }
        }
    }
}

和简单多边形:

/regions/_doc/1
{
    "location" : {
        "type" : "polygon",
        "coordinates" : [
            [ 
                [53.847332102970626,27.485155519098047],
                [53.84626875748117,27.487134989351038],
                [53.8449047241684,27.48501067981124],
                [53.84612634308789,27.482945378869765],
                [53.847411219859,27.48502677306532],
                [53.847332102970626,27.485155519098047] 
            ]
        ]
    }
}

根据文档,我只能搜索多边形内的坐标,只有当多边形包含在请求geo polygon查询中时,但我需要在查询中按坐标查找多边形。elasticsearch 7.6版本。
查询:

{
  "query": {
    "match_all": {}
  },
  "filter": {
    "geo_shape": {
      "geometry": {
        "shape": {
          "coordinates": [
            53.846415,
            27.485756
          ],
          "type": "point"
        },
        "relation": "whithin"
      }
    }
  }
}
czq61nw1

czq61nw11#

您走的是正确的道路,但您的查询格式严重错误。解决方法如下:

{
  "query": {
    "bool": {
      "filter": {
        "geo_shape": {
          "location": {
            "shape": {
              "coordinates": [
                53.846415,
                27.485756
              ],
              "type": "point"
            },
            "relation": "intersects"
          }

        }
      }
    }
  }
}

注意我是怎么用的 intersects 而不是 within . 这个答案解释了原因。

相关问题