弹性:存储“FeatureCollection"类型的 GeoJSON,并进行查询 [英] Elastic: storing GeoJSONs of type `FeatureCollection`, and query
问题描述
我使用 Elastic 7.x 来存储这样的文档:
<代码>{id":polygon_tests_01.ast-ORTHOMOSAIC",名称":tmpl_integration_test_GeoTIFF",地区":{类型":特征集合",特点":[{类型":功能",几何":{坐标":[[[-149.67474372431124,61.27942558978003],[-149.65726554157862,60.993770332779064],[-150.11544465434918,61.15680203118899],[-149.87699170822603,61.28122531469481],[-149.67474372431124,61.27942558978003]]],类型":多边形"},属性":{}}],类型":功能",属性":{}}……更多数据……}
尝试为其创建映射,我使用:
<代码>{映射":{属性":{地区":{属性":{功能":{属性":{几何":{类型":geo_shape";}}}}}}}}
首先 - 这是正确的映射方式吗?
其次,假设我想创建一个查询,从弹性所有具有相交区域"的文档中获取.我使用这个查询:
<代码>{查询":{地理形状":{区域.特征.几何":{关系":相交",形状":{类型":多边形",坐标":[[[10.526270711323841,10.444489244321758],[11.925063668547947,10.371171909552444],[11.070002142972083,9.364612094349482],[10.526270711323841,10.444489244321758]]]}}}}}
唉,我收到一个错误:
未能找到 geo_shape 字段 [region.features.geometry]
那么我如何存储标准化"?FeatureCollection
类型的 GeoJSON,并进行下降查询?
ES 确实支持 GeometryCollections
但需要一些预处理
I work with Elastic 7.x to store documents like this:
{
"id": "polygon_tests_01.ast-ORTHOMOSAIC",
"name": "tmpl_integration_test_GeoTIFF",
"region": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"coordinates": [[[-149.67474372431124,61.27942558978003],
[-149.65726554157862,60.993770332779064],
[-150.11544465434918,61.15680203118899],
[-149.87699170822603,61.28122531469481],
[-149.67474372431124,61.27942558978003]]],
"type": "Polygon"
},
"properties": {}
}
],
"type": "Feature",
"properties": {}
}
... more data...
}
Trying to create a mapping for it, i use:
{
"mappings": {
"properties": {
"region": {
"properties": {
"features": {
"properties": {
"geometry": {
"type": "geo_shape"
}
}
}
}
}
}
}
}
First - is this the correct way to map?
Second, suppose I want to create a query the fetches from elastic all documents with intersecting "regions". I use this query:
{
"query": {
"geo_shape": {
"region.features.geometry": {
"relation": "intersects",
"shape": {
"type": "polygon",
"coordinates": [[[10.526270711323841,10.444489244321758],
[11.925063668547947,10.371171909552444],
[11.070002142972083,9.364612094349482],
[10.526270711323841,10.444489244321758]
]]
}
}
}
}
}
Alas, I get an error :
failed to find geo_shape field [region.features.geometry]
So how can I store "normalized" GeoJSONs of type FeatureCollection
, and make a descent query?
ES does support GeometryCollections
but a bit of pre-processing is required.
Going with a minimum reproducible index setup:
PUT geoindex
{
"mappings": {
"properties": {
"regions": {
"type": "geo_shape"
}
}
}
}
Extract the features
to conform w/
POST geoindex/_doc
{
"id": "polygon_tests_01.ast-ORTHOMOSAIC",
"name": "tmpl_integration_test_GeoTIFF",
"regions": {
"type": "geometrycollection",
"geometries": [
{
"type": "polygon",
"coordinates": [[[-149.67474372431124,61.27942558978003],[-149.65726554157862,60.993770332779064],[-150.11544465434918,61.15680203118899],[-149.87699170822603,61.28122531469481],[-149.67474372431124,61.27942558978003]]]
}
]
}
}
Notice that regions.geometries
can include multiple geojson features, not just polygons.
After that, we can query for polygon intersections:
POST geoindex/_search
{
"query": {
"geo_shape": {
"regions": {
"relation": "intersects",
"shape": {
"type": "polygon",
"coordinates": [[[-149.68734741210938,61.34276125480617],[-149.78347778320312,61.268912537559316],[-149.53628540039062,61.18628656437939],[-149.37286376953125,61.29662618671741],[-149.4085693359375,61.3671195097931],[-149.65164184570312,61.37962043716795],[-149.68734741210938,61.34276125480617]]]
}
}
}
}
}
Note: your indexed polygon is in Anchorage, AK, while the one in the query is in eastern Nigeria. The two ain't gonna overlap :)
So my query above tests the purple polygon around Eagle River:
这篇关于弹性:存储“FeatureCollection"类型的 GeoJSON,并进行查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!