elasticsearch - 多边形查询中的 Elasticsearch 点
问题描述
我在用着Elasticsearch V6.7.1.
我创建了几个索引并用数据填充它们。每个索引都有一个
gps_coords
带有lat and
lon 值(坐标)的字段
我想要做的是编写一个查询,我在其中传递一个多边形并检查某个点是否落入该多边形,这可能吗?
这是我已经尝试过的查询:
{
"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
field 而不是gps_coords
,如评论中所述。但我相信这只是一个错字,因为这不是错误的根源。
geo_shape
您收到解析异常的原因是您在查询的多边形定义中缺少一对括号。在这里查看正确的表格。正确的形式是(只是相关部分):
"shape": {
"type": "polygon",
"coordinates" : [
[[25.0245351, 54.5693374],
[25.0245351, 54.83232],
[25.4815808, 54.83232],
[25.4815808, 54.5693374],
[25.0245351, 54.5693374]]
]
}
推荐阅读
- c++ - 根据平台目标修改 OriginalFilename 字符串
- header - 制作和 HttpPOST 操作时出现 Microsoft 刷新卡问题
- unit-testing - 安装 go lang 后无法运行 go test 程序
- html - 媒体查询似乎不起作用
- java - 访问从 TabPane 返回的 Tab 内的 JavaFX TextArea
- javascript - ResizeObserver 一对多性能
- amazon-web-services - AWS-我有一个将 Lambda 函数与 API 网关集成的 CFT。我使用哪些资源将我的 API 网关连接到自定义 DNS 名称?
- java - 如何在android中制作自定义Arrays.asList
- java - java.util.StringTokenizer.nextToken 处的线程“main”java.util.NoSuchElementException 中的异常(未知来源)
- javascript - 为什么jQuery点击功能不起作用?