elasticsearch - Elasticsearch 中的 geo_shape 的 FeatureCollection

标签 elasticsearch geojson

将 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: Featuretype: FeatureCollection 字段)并添加一个映射说:

"features": {
    "geometry": {
      "type": "geo_shape"
    }
}

这似乎工作正常,但感觉不对,因为我给出了一个 geometry 数组。 这样可以吗?或者将 FeatureCollection 转换为类型 geometrycollection 是正确的方法吗?这显然需要多个 geometry 元素。

一个后续问题,我可以做一个查询吗:在一个查询中给我元素 X 内的所有几何元素(其中 X 也在索引中),而不是获取 X 而不是执行多个跟进每个多边形的查询?

最佳答案

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
  • 使用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/

相关文章:

c# - Elasticsearch-计算数组中(不可预测的)字符串的出现

elasticsearch - 在 Elasticsearch 中定义字符串数组字段

elasticsearch - 如何正确初始化Elasticsearch查询?

google-maps - 确定 Google Maps API 中 Geojson 的绘制何时完成

javascript - D3 映射与 geoJson 美国 map 工作但不工作世界

elasticsearch - 无法使通配符查询在Elasticsearch中的多个字段上工作

elasticsearch - 如何使Logstash每天运行一次并在作业完成后自动停止

javascript - 如何从 map 上删除所有图层?

javascript - SVG不绘制图形

javascript - Mapbox simplestyle 会阻止 popupContent?使用 pointToLayer 和 onEachFeature