将 geojson FeatureCollection 转换为 es geo_shape 的正确方法是什么?
我有一个如下所示的 FeatureCollection:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [[[1.96, 42.455],[1.985,42.445]]]
}
},
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [...]
}
}
]
}
我如何将其转换为 es geo_shape
。
目前我只是像那样索引它(删除 type: Feature
和 type: FeatureCollection
字段)并添加一个映射说:
"features": {
"geometry": {
"type": "geo_shape"
}
}
这似乎工作正常,但感觉不对,因为我给出了一个 geometry
数组。
这样可以吗?或者将 FeatureCollection
转换为类型 geometrycollection
是正确的方法吗?这显然需要多个 geometry
元素。
一个后续问题,我可以做一个查询吗:在一个查询中给我元素 X 内的所有几何元素
(其中 X 也在索引中),而不是获取 X 而不是执行多个跟进每个多边形的查询?
最佳答案
GeometryCollection可能是您正在寻找的。p>
所以如果你有这个:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [[[1.96, 42.455],[1.985,42.445]]]
}
},
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [...]
}
}
]
}
你可以像这样在 ES 中索引它:
PUT example
{
"mappings": {
"doc": {
"properties": {
"location": {
"type": "geo_shape"
}
}
}
}
}
POST /example/doc
{
"location" : {
"type": "geometrycollection",
"geometries": [
{
"type": "Polygon",
"coordinates": [[[1.96, 42.455],[1.985,42.445]]]
},
{
"type": "Polygon",
"coordinates": [...]
}
]
}
}
所以基本上,您只需要:
- 将
FeatureCollection
更改为geometrycollection
- 将
features
更改为geometries
- 使用
geometry
内部对象填充geometries
数组
关于您的查询,您可以这样做:
POST /example/_search
{
"query":{
"bool": {
"filter": {
"geo_shape": {
"location": {
"shape": {
"type": "envelope",
"coordinates" : [[13.0, 53.0], [14.0, 52.0]]
},
"relation": "within"
}
}
}
}
}
}
within
关系返回其 geo_shape
字段在查询中给定的几何图形内的所有文档。
关于elasticsearch - Elasticsearch 中的 geo_shape 的 FeatureCollection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51761480/