# Mapping geo\_shape dynamically

**URL:** <https://discuss.elastic.co/t/mapping-geo-shape-dynamically/284483>\
**Category:** Elasticsearch\
**Created:** [September 17, 2021, 12:32pm UTC](https://discuss.elastic.co/t/mapping-geo-shape-dynamically/284483 "2021-09-17T12:32:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dersmon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dersmon/32/94719_2.png) [@dersmon](https://discuss.elastic.co/u/dersmon)\
**Post date:** [September 17, 2021, 12:32pm UTC](https://discuss.elastic.co/t/mapping-geo-shape-dynamically/284483/1 "2021-09-17T12:32:12Z")

</div>

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:

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

```

Which lets me run searches using the [geo queries](https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-queries.html), 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.

---

<div class="post-metadata">

**Author:** ![dersmon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dersmon/32/94719_2.png) [@dersmon](https://discuss.elastic.co/u/dersmon)\
**Post date:** [September 21, 2021, 6:04am UTC](https://discuss.elastic.co/t/mapping-geo-shape-dynamically/284483/2 "2021-09-21T06:04:26Z")

</div>

Short follow up.

Using a dynamic template like this:

```json
        {
            "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:

```json
{
  "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?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 19, 2021, 6:05am UTC](https://discuss.elastic.co/t/mapping-geo-shape-dynamically/284483/3 "2021-10-19T06:05:08Z")

</div>

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