我有一个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
元素。
一个跟进问题,我可以在一个查询中查询la:Give me all elements geometrically inside Element X
(其中X也在索引中),而无需获取X并且可以对每个多边形进行多个跟进查询?
答案 0 :(得分:3)
GeometryCollection可能正是您想要的。
所以,如果您有这个:
{
"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
geometries
内部对象填充geometry
数组关于您的查询,您可以这样做:
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
字段在查询给定的几何范围内的所有文档。