问题描述
我有一个FeatureCollection看起来像这样:
I have a FeatureCollection looking like this:
{
"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
字段)并添加一个映射:
How can I translate this into the es geo_shape
.Currently I just index it like that (dropping type: Feature
and type: FeatureCollection
fields) and add a mapping saying:
"features": {
"geometry": {
"type": "geo_shape"
}
}
这似乎很好用,但是由于我给出了一个 geometry
s数组,所以感觉不对.可以吗?还是正确的方法是将 FeatureCollection
转换为 geometrycollection
?显然需要多个 geometry
元素.
This seems to work fine, but feels wrong, as I give an array of geometry
s.Is this okay or would the right way be to translate the FeatureCollection
to type geometrycollection
? Which clearly wants multiple geometry
elements.
一个后续问题,我可以对一个查询进行查询吗:在一个查询中给我几何上所有包含在元素X内的元素
(其中X也在索引中),而无需获取X且要执行多个跟进每个多边形的查询?
One Followup question, can I do a query a la: Give me all elements geometrically inside Element X
(where X is also in the index) in one query, without fetching X and than doing multiple follow up queries for each polygon?
推荐答案
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中对其进行索引:
You can index it in ES like this:
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": [...]
}
]
}
}
因此,基本上,您只需要:
So basically, you simply need to:
- 将
FeatureCollection
更改为geometrycollection
- 将
功能
更改为几何形状
- 使用
geometry
内部对象 填充
geometries
数组- change
FeatureCollection
togeometrycollection
- change
features
togeometries
- populate the
geometries
array with thegeometry
inner-objects
关于您的查询,您可以这样做:
Regarding your query, you can do it like this:
POST /example/_search
{
"query":{
"bool": {
"filter": {
"geo_shape": {
"location": {
"shape": {
"type": "envelope",
"coordinates" : [[13.0, 53.0], [14.0, 52.0]]
},
"relation": "within"
}
}
}
}
}
}
in
之间的关系将返回其 geo_shape
字段在查询中指定的几何范围内的所有文档.
The within
relationship returns all documents whose geo_shape
field is within the geometry given in the query.
这篇关于在Elasticsearch中将FeatureCollection转换为geo_shape的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!