# How to remove dynamic field from mapping with Elastic Reindex API

**URL:** https://discuss.elastic.co/t/how-to-remove-dynamic-field-from-mapping-with-elastic-reindex-api/363598
**Category:** Elastic Search
**Tags:** painless, reindex
**Created:** [July 23, 2024, 2:37am UTC](https://discuss.elastic.co/t/how-to-remove-dynamic-field-from-mapping-with-elastic-reindex-api/363598 "2024-07-23T02:37:44Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![sedwardsgt](https://avatars.discourse-cdn.com/v4/letter/s/9fc29f/32.png) [@sedwardsgt](https://discuss.elastic.co/u/sedwardsgt)
#### Post date: [July 23, 2024, 2:37am UTC](https://discuss.elastic.co/t/how-to-remove-dynamic-field-from-mapping-with-elastic-reindex-api/363598/1 "2024-07-23T02:37:44Z")

</div>

We have a dynamic field defined in multiple indexes that is of type `geo_shape`, and uses the `points_only` param. Due to a) the [deprecation](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/breaking-changes-7.0.html#deprecated-geo-shape-params) of `points_only` in version 7.x, and b) the fact that we don't use that field any more, we want to remove it from the mapping and the data, although the mapping is the most important, since we don't search on that field.

First, here is the mapping definition:

```auto
"mappings": {
    "dynamic_templates": [
        {
            "base_geo": {
                "match": "*Geo",
                "mapping": {
                    "points_only": true,
                    "type": "geo_shape"
                }
            }
        },
    ...
    ]
}

```

It appears that the [Reindex API](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html) can be used to do this, since in order to remove a field from a mapping, a new index has to be created. As such, I've been trying variations on this to `POST _reindex`

```auto
{
    "source": {
        "index": "local_federal_agency_models_1708127195"
    },
    "dest": {
        "index": "local_federal_agency_models_1708127195_3"
    },
    "script": {
        "source": "ctx._source.remove('base_geo')"
    }
}

```

However, this not only removes the `base_geo` field, but it removes the entire `dynamic_templates` array, so it removes all dynamic mappings.  
As for the documents themselves, I know I can use an [ingest pipeline](https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest.html), but how can I just remove my `base_geo` field mapping when re-indexing?

---

<div class="post-metadata">

### Author: ![Sander\_Philipse](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sander_philipse/32/101890_2.png) [@Sander\_Philipse](https://discuss.elastic.co/u/Sander_Philipse)
#### Post date: [July 24, 2024, 8:35am UTC](https://discuss.elastic.co/t/how-to-remove-dynamic-field-from-mapping-with-elastic-reindex-api/363598/2 "2024-07-24T08:35:41Z")

</div>

Hi @sedwardsgt, a reindex operation does not copy the mapping definition of the original index. It only copies the source data (_not_ the mapped data) from one index to the other.

To achieve your intended purpose, you should:

1. Create a new empty index
2. Set the mapping of that index to what you want it to be. In this case that's presumably the same as the source index, but without your `base_geo` dynamic template mapping
3. Run reindex from the original index to the new index

---

<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: [August 21, 2024, 8:36am UTC](https://discuss.elastic.co/t/how-to-remove-dynamic-field-from-mapping-with-elastic-reindex-api/363598/3 "2024-08-21T08:36:38Z")

</div>

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