Elastic:存储“FeatureCollection”类型的 GeoJSON,并进行查询

Elastic: storing GeoJSONs of type `FeatureCollection`, and query

我使用 Elastic 7.x 来存储这样的文档:

{
    "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...
    
}

尝试为其创建映射,我使用:

{
    "mappings": {
        "properties": {
            "region": {
                "properties": {
                    "features": {
                        "properties": {
                            "geometry": {
                              "type": "geo_shape"
                            }
                        }
                    }
                }
            }
        }
    }
}

首先 - 这是正确的映射方式吗?

其次,假设我想创建一个查询,从弹性所有具有相交“区域”的文档中提取数据。我使用这个查询:

{
  "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]
            ]]
        }
      }
    }
  }
}

唉,我得到一个错误:

failed to find geo_shape field [region.features.geometry]

那么如何存储 FeatureCollection 类型的“规范化”GeoJSON 并进行下降查询?

ES 确实支持 GeometryCollections 但需要一些预处理 is required.

采用最小可重现索引设置:

PUT geoindex
{
  "mappings": {
    "properties": {
      "regions": {
        "type": "geo_shape"
      }
    }
  }
}

提取 features 以符合 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]]]
      }
    ]
  }
}

请注意 regions.geometries 可以包含多个 geojson 特征,而不仅仅是多边形。

之后,我们可以查询多边形交点:

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]]]
        }
      }
    }
  }
}

注意:您的索引多边形位于阿拉斯加州安克雷奇,而查询中的多边形位于尼日利亚东部。两者不会重叠:)

所以我上面的查询测试了鹰河周围的紫色多边形: