# Changing mapping fields structure flow

**URL:** <https://discuss.elastic.co/t/changing-mapping-fields-structure-flow/243576>\
**Category:** Elasticsearch\
**Created:** [August 3, 2020, 1:21pm UTC](https://discuss.elastic.co/t/changing-mapping-fields-structure-flow/243576 "2020-08-03T13:21:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gitterhh](https://avatars.discourse-cdn.com/v4/letter/g/b19c9b/32.png) [@gitterhh](https://discuss.elastic.co/u/gitterhh)\
**Post date:** [August 3, 2020, 1:21pm UTC](https://discuss.elastic.co/t/changing-mapping-fields-structure-flow/243576/1 "2020-08-03T13:21:29Z")

</div>

I have an index with the mappings

```auto
{
   "mappings": {
      "properties": {
         "title": {
            "type": "text"
         },
         "location": {
            "type": "keyword"
         }
      }
   }
}

```

In `location` field at the moment we are storing the city name.  
And we need to change the mapping structure to store also the country and state, so the mapping will be

```auto
{
   "mappings": {
      "properties": {
         "title": {
            "type": "text"
         },
         "location": {
            "properties": {
                "country": {
                    "type": "keyword"
                },
                "state": {
                    "type": "keyword"
                },
                "city": {
                    "type": "keyword"
                }
            }
         }
      }
   }
}

```

What is the recommended flow for such migration?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 4, 2020, 9:50am UTC](https://discuss.elastic.co/t/changing-mapping-fields-structure-flow/243576/2 "2020-08-04T09:50:57Z")

</div>

This requires a full reindexing operation, as you are changing the structure of a field from a keyword to a full blown object. This will not work on an existing index, but requires a new one with a new mapping.

You could use the [reindex API](https://www.elastic.co/guide/en/elasticsearch/reference/7.8/docs-reindex.html) in combination with a script or an index pipeline to achieve this by changing the JSON before it gets indexed into 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:** [September 1, 2020, 9:50am UTC](https://discuss.elastic.co/t/changing-mapping-fields-structure-flow/243576/3 "2020-09-01T09:50:58Z")

</div>

Closed on September 1, 2020, 9:50am UTC

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