Elasticsearch获取坐标的交点
Elasticsearch get intersection of coordinates
我有一个索引 field
,给定多边形的一组坐标,我想通过它获取与这些坐标相交的任何字段。考虑到使用 elasticsearch
地理位置特征的 field
索引的结构,这是否可能?我正在使用 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"
}
}
}
}
}
}
当然可以。根据您的用例调整 :
- 设置索引映射
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]]]
}
}
}
}
}
我有一个索引 field
,给定多边形的一组坐标,我想通过它获取与这些坐标相交的任何字段。考虑到使用 elasticsearch
地理位置特征的 field
索引的结构,这是否可能?我正在使用 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"
}
}
}
}
}
}
当然可以。根据您的用例调整
- 设置索引映射
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]]]
}
}
}
}
}