在 ElasticSearch 中将 GeoShape/Polygon 文档与 GeoPoint 查询匹配
Match a GeoShape/Polygon document with a GeoPoint query in ElasticSearch
我想匹配 ES 索引中的任何文档,其中一个点在文档多边形 geo_shape 类型内。
基本上,我想查询一个点(即 [2.934211, 42.522377]),并匹配多边形与该点相交的所有文档。
这是我的简单 ES 映射:
{"geometry":{"type":"geo_shape","tree":"quadtree","precision":"1m"}}
这是一个索引文档:
{
"geometry": {
"type": "polygon",
"coordinates": [
[
[
2.9109533049198
,
42.525105483878
]
,
[
2.9110769445829
,
42.531703894436
]
,
[
2.9032846986744
,
42.539733810015
]
,
[
2.9030996511561
,
42.556013979376
]
,
[
2.9131331966995
,
42.562962734203
]
,
[
2.9135244444206
,
42.569759384018
]
,
[
2.917877044124
,
42.57088655519
]
,
[
2.9319395143989
,
42.568900684816
]
,
[
2.9403405122874
,
42.572016209123
]
,
[
2.9363870185385
,
42.561333977005
]
,
[
2.9309712722105
,
42.534037916636
]
,
[
2.9109533049198
,
42.525105483878
]
]
]
}
当我在索引中搜索并使用 geo_shape 筛选器键入时:
{
"query": {
"match_all": {}
},
"filter": {
"geo_shape": {
"geometry": {
"relation": "intersects",
"shape": {
"coordinates": [
2.934211,
42.522377
],
"type": "point"
}
}
}
}
}
我没有结果:
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": [ ]
}
}
知道我遗漏了什么吗?我也尝试过 "within" 的关系,但没有成功。
谢谢,
DJP
您的点不在多边形内!
查询无效。我更正了它们:
映射查询(类型 = doc):
{
"mappings": {
"doc": {
"properties": {
"geometry": {
"type": "geo_shape","tree":"quadtree","precision":"1m"
}
}
}
}
}
搜索查询
{
"query": {
"bool": {
"must": {
"match_all": {
}
},
"filter": {
"geo_shape": {
"geometry": {
"shape": {
"coordinates": [
2.934211,
42.522377
],
"type": "point"
},
"relation": "disjoint"
}
}
}
}
}
}
我想匹配 ES 索引中的任何文档,其中一个点在文档多边形 geo_shape 类型内。
基本上,我想查询一个点(即 [2.934211, 42.522377]),并匹配多边形与该点相交的所有文档。
这是我的简单 ES 映射:
{"geometry":{"type":"geo_shape","tree":"quadtree","precision":"1m"}}
这是一个索引文档:
{
"geometry": {
"type": "polygon",
"coordinates": [
[
[
2.9109533049198
,
42.525105483878
]
,
[
2.9110769445829
,
42.531703894436
]
,
[
2.9032846986744
,
42.539733810015
]
,
[
2.9030996511561
,
42.556013979376
]
,
[
2.9131331966995
,
42.562962734203
]
,
[
2.9135244444206
,
42.569759384018
]
,
[
2.917877044124
,
42.57088655519
]
,
[
2.9319395143989
,
42.568900684816
]
,
[
2.9403405122874
,
42.572016209123
]
,
[
2.9363870185385
,
42.561333977005
]
,
[
2.9309712722105
,
42.534037916636
]
,
[
2.9109533049198
,
42.525105483878
]
]
]
}
当我在索引中搜索并使用 geo_shape 筛选器键入时:
{
"query": {
"match_all": {}
},
"filter": {
"geo_shape": {
"geometry": {
"relation": "intersects",
"shape": {
"coordinates": [
2.934211,
42.522377
],
"type": "point"
}
}
}
}
}
我没有结果:
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": [ ]
}
}
知道我遗漏了什么吗?我也尝试过 "within" 的关系,但没有成功。
谢谢, DJP
您的点不在多边形内!
查询无效。我更正了它们:
映射查询(类型 = doc):
{
"mappings": {
"doc": {
"properties": {
"geometry": {
"type": "geo_shape","tree":"quadtree","precision":"1m"
}
}
}
}
}
搜索查询
{
"query": {
"bool": {
"must": {
"match_all": {
}
},
"filter": {
"geo_shape": {
"geometry": {
"shape": {
"coordinates": [
2.934211,
42.522377
],
"type": "point"
},
"relation": "disjoint"
}
}
}
}
}
}