Mapping geo_shape dynamically

I struggle to find a generic mapping for my GeoJSON data in 7.14.0.

My documents are created using a composition pattern. This results in a collection document types that may have a field "geometry" containing GeoJSON GeometryCollections somewhere within their geometry.

I created a simple mapping like this:

{
    "properties": {
(...)
        "geometry": {
            "type": "geo_shape"
        }
    },
(...)

Which lets me run searches using the geo queries, but only returns documents where geometry is a top level key.

How should I go about changing this to a more generic/dynamic mapping that indexes every occurrence of a "geometry" as one field? I tried changing this into a dynamic template, but so far failed to get it working.

Short follow up.

Using a dynamic template like this:

        {
            "geometry": {
              "match": "geometry",
              "match_mapping_type": "object",
              "mapping": {
                "type": "geo_shape"
              }
            }
        }

I can use "geometry" or "path.to.a.nested.geometry" in a distance filter:

{
  "query": {
    "bool": {
      "must": {
        "match_all": {}
      },
      "filter": [
          {
            "geo_distance": {
            "distance": "10km",
            "path.to.a.nested.geometry": {
                "lat": <value>,
                "lon": <value>
                }
              }
          }
        ]
    }
  }
}

Now I would have to build an OR filter for all my possible geometry fields. Or is it possible to index all fields with a shared field name, so that I only have to create one filter?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.