多边形查询中的弹性搜索点

问题描述 投票:0回答:2

我正在使用Elasticsearch V6.7.1.

我创建了几个索引并用数据填充它们。每个索引都有一个字段gps_coordslat andlon`值(坐标)

我想要做的是写一个查询,我传递一个多边形并检查某个点是否属于该多边形,这可能吗?

这是我已经尝试过的查询:

{
    "query": {
        "bool" : {
            "must" : {
                "match_all" : {}
            },
             "filter": {
                "geo_shape": {
                    "location": {
                        "shape": {
                            "type": "polygon",
                            "coordinates" : [
                                [25.0245351, 54.5693374], 
                                [25.0245351, 54.83232],
                                [25.4815808, 54.83232],
                                [25.4815808, 54.5693374],
                                [25.0245351, 54.5693374]
                              ]
                        },
                        "relation": "within"
                    }
                }
            }
        }
    }
}

但它返回此错误:

{
  "error": {
    "root_cause": [
      {
        "type": "parse_exception",
        "reason": "Invalid LinearRing found. Found a single coordinate when expecting a coordinate array"
      }
    ],
    "type": "parse_exception",
    "reason": "Invalid LinearRing found. Found a single coordinate when expecting a coordinate array"
  },
  "status": 400
}

这是我的索引映射:

[
            'index' => 'places',
            'body' => [
                'mappings' => [
                    'place' => [
                        "properties" => [
                            "gps_coords" => [
                                "ignore_malformed" => true,
                                "type" => "geo_shape"
                            ]
                        ]
                    ],

                ],
                "number_of_replicas" => 0
            ]
        ]
    ];

有人可以指出我正确的方向。 谢谢 !

elasticsearch geospatial spatial elastic-stack spatial-query
2个回答
0
投票

首先,在查询示例中,您使用location字段而不是gps_coords,如评论中所述。但我认为这只是一个错字,因为这不是错误的来源。

您收到解析异常的原因是您在geo_shape查询中缺少多边形定义中的一对括号。看到正确的形式here。正确的形式是(只是相关部分):

"shape": {
    "type": "polygon",
    "coordinates" : [
        [[25.0245351, 54.5693374], 
         [25.0245351, 54.83232],
         [25.4815808, 54.83232],
         [25.4815808, 54.5693374],
         [25.0245351, 54.5693374]]
    ]
}

0
投票

是的,对不起,我的不好,只是从ES文档复制了示例而不是我的代码。 Okey,会尝试添加这些括号,看看它是否有帮助,谢谢!

© www.soinside.com 2019 - 2024. All rights reserved.