我有一个索引field,给定一个多边形的一组坐标,我想得到任何与这些坐标相交的字段。考虑到使用field地理位置特性的elasticsearch索引的结构,这有可能吗?我正在使用elasticsearch版本7.9
{
"geo_json": {
"geometry": {
"coordinates": [
[
[
2.1228971832029644,
41.3011586218355
],
[
2.122596585111679,
41.3012384865674
],
[
2.1221786804481835,
41.30191870980272
],
[
2.1223509744761158,
41.302042636348716
],
[
2.1226735685285507,
41.30192972550523
],
[
2.1232820963718857,
41.30165984025794
],
[
2.1232820963718857,
41.30131559725024
],
[
2.1228971832029644,
41.3011586218355
]
]
],
"type": "Polygon"
},
"properties": null,
"type": "Feature"
},
"name": "Barcelona"
}使用返回的错误"Field [geo_json.geometry.coordinates] is of unsupported type [float]. [geo_shape] query supports the following types [geo_shape,geo_point]",我尝试了以下查询
GET field/_search
{
"query": {
"bool": {
"filter": {
"geo_shape": {
"geo_json.geometry.coordinates": {
"shape": {
"type": "polygon",
"coordinates": [
[
[
2.1228971832029644,
41.3011586218355
],
[
2.122596585111679,
41.3012384865674
],
[
2.1221786804481835,
41.30191870980272
],
[
2.1223509744761158,
41.302042636348716
],
[
2.1226735685285507,
41.30192972550523
],
[
2.1232820963718857,
41.30165984025794
],
[
2.1232820963718857,
41.30131559725024
],
[
2.1228971832029644,
41.3011586218355
]
]
]
},
"relation": "intersects"
}
}
}
}
}
}发布于 2021-02-15 11:29:20
这当然是可能的。使my previous answer适应您的用例:
PUT geoindex
{
"mappings": {
"properties": {
"area": {
"type": "float"
},
"center": {
"type": "geo_point"
},
"geo_json": {
"type": "geo_shape"
},
"name": {
"type": "text"
}
}
}
}POST geoindex/_doc
{
"area": 5380.8444064004625,
"center": [ 2.1227303884100346, 41.30160062909211 ],
"geo_json": {
"type": "polygon",
"coordinates": [[[2.1228971832029644,41.3011586218355],[2.122596585111679,41.3012384865674],[2.1221786804481835,41.30191870980272],[2.1223509744761158,41.302042636348716],[2.1226735685285507,41.30192972550523],[2.1232820963718857,41.30165984025794],[2.1232820963718857,41.30131559725024],[2.1228971832029644,41.3011586218355]]]
},
"name": "Barcelona"
}POST geoindex/_search
{
"query": {
"geo_shape": {
"geo_json": {
"relation": "intersects",
"shape": {
"type": "polygon",
"coordinates": [[[2.122421264648437,41.30061251600798],[2.123579978942871,41.300354591849114],[2.123579978942871,41.30120896171846],[2.122957706451416,41.30129762210163],[2.122421264648437,41.30061251600798]]]
}
}
}
}
}

https://stackoverflow.com/questions/66206311
复制相似问题