# Are there any tools to facilitate changing a mapping?

**URL:** https://discuss.elastic.co/t/are-there-any-tools-to-facilitate-changing-a-mapping/123447
**Category:** Elasticsearch
**Created:** [March 11, 2018, 8:30pm UTC](https://discuss.elastic.co/t/are-there-any-tools-to-facilitate-changing-a-mapping/123447 "2018-03-11T20:30:18Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![David9](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/david9/32/42150_2.png) [@David9](https://discuss.elastic.co/u/David9)
#### Post date: [March 11, 2018, 8:30pm UTC](https://discuss.elastic.co/t/are-there-any-tools-to-facilitate-changing-a-mapping/123447/1 "2018-03-11T20:30:19Z")

</div>

I have to modify an index mapping and I feel like when doing this in the past it feels more difficult and error-prone than it should be. Specifically I have to modify a geopoint field. I'm going to use a json text editor and then delete the existing mapping and then update to the new mapping, using the console in kibana. But editing mappings really requires a lot of care because of the json nesting ... I guess I should copy the existing mapping, then modify it and post it back to the server? are there any tools that facilitate this process? thanks

---

<div class="post-metadata">

### Author: ![yaauie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yaauie/32/23363_2.png) [@yaauie](https://discuss.elastic.co/u/yaauie)
#### Post date: [March 11, 2018, 10:49pm UTC](https://discuss.elastic.co/t/are-there-any-tools-to-facilitate-changing-a-mapping/123447/2 "2018-03-11T22:49:42Z")

</div>

> then delete the existing mapping

Unfortunately, while we can delete a mapping _template_, we can't actually delete mappings themselves [[1](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-mapping.html)]; this is because a mapping is the thing that binds all of our data together, and without it, Elasticsearch wouldn't know how to apply a new mapping to the bits that are distributed across our cluster so deleting a mapping is effectively the same as deleting all of the data in an index 😩.

There are two paths forward, depending on whether or not downtime is acceptable.

- If you can stop your input stream, the [Elasticsearch \_reindex API](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html) may be a great option; it effectively copies all documents from one index to another _previously configured index_, optionally transforming each document with a script; after deleting the old index, you can then add an [Index Alias](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html) if necessary.
- Otherwise, you may need to do a phased migration; since we can _add_ fields to an existing index, we can dual-write the new representation to a new field alongside the existing old field, migrate the existing data, then update our application to just use the new field instead.

The phases look something like this:

## starting state

_we start in a state where applications are using field `foo`, but the mappings are insufficient for future use_

## prep phase

- index template updated to _add_ new mapping `bar`
- existing indexes updated to add new mapping `bar`
- applications configured to _dual-write_ to `foo` and new mapping `bar`

_at this point, our applications are still reading from `foo`, but new data is being persisted to both `foo` and `bar`_

## migration phase

- Logstash, [Elasticsearch \_update\_by\_query API](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html), or some other tool iterates over all documents, reading from `foo`, transforming and persisting field `bar` that has our new mapping

_at this point, our applications are still reading from `foo`, but data has also been fully migrated to `bar`_

## end phase

- applications updated to read from `bar`
- applications updated to stop dual-writing to `foo`, and only write to `bar`

_at this point, we're fully using the new field `bar`, but there's a little cleanup left_

## post-migration cleanup

- index _templates_ updated to remove mapping `foo` (this means new indices will never create the `foo` field)
- optionally, sweep through existing indices to unset `foo` since it is no longer used

---

<div class="post-metadata">

### Author: ![David9](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/david9/32/42150_2.png) [@David9](https://discuss.elastic.co/u/David9)
#### Post date: [March 12, 2018, 7:22pm UTC](https://discuss.elastic.co/t/are-there-any-tools-to-facilitate-changing-a-mapping/123447/3 "2018-03-12T19:22:28Z")

</div>

Thanks very much, this helps alot.

---

<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: [April 9, 2018, 7:22pm UTC](https://discuss.elastic.co/t/are-there-any-tools-to-facilitate-changing-a-mapping/123447/4 "2018-04-09T19:22:43Z")

</div>

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