gpt4 book ai didi

elasticsearch - 多边形查询中的Elasticsearch点

转载 作者:行者123 更新时间:2023-12-03 00:49:31 25 4
gpt4 key购买 nike

我正在使用Elasticsearch V6.7.1.
我创建了一些索引,并用数据填充了它们。每个索引都有一个字段
带有gps_coords lon`值的lat and(坐标)

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

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

{
"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
]
]
];

有人能指出我正确的方向吗?
谢谢 !

最佳答案

首先,在查询示例中,使用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]]
]
}

关于elasticsearch - 多边形查询中的Elasticsearch点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55893168/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com