# How to change mapping and reindex to new index using mapping with Python Elasticsearch client API?

**URL:** <https://discuss.elastic.co/t/how-to-change-mapping-and-reindex-to-new-index-using-mapping-with-python-elasticsearch-client-api/51015>\
**Category:** Elasticsearch\
**Created:** [May 26, 2016, 5:04am UTC](https://discuss.elastic.co/t/how-to-change-mapping-and-reindex-to-new-index-using-mapping-with-python-elasticsearch-client-api/51015 "2016-05-26T05:04:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![timogoosen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timogoosen/32/29750_2.png) [@timogoosen](https://discuss.elastic.co/u/timogoosen)\
**Post date:** [May 26, 2016, 5:04am UTC](https://discuss.elastic.co/t/how-to-change-mapping-and-reindex-to-new-index-using-mapping-with-python-elasticsearch-client-api/51015/1 "2016-05-26T05:04:23Z")

</div>

Hi I'd like to use the client API to do the following.

1. Set mapping for new index to reindex data to. Let's call our new index "new-index"
2. Reindex data from let's say "old-index" to new-index, but keep the mapping that  
we set for new-index.

How do I do this with the elasticsearch python client API?  
I thought I would be able to do this by creating an index "new-index" with a mapping and then  
just reindexing "old-index" to "new-index", but it doesn't seem to keep the mapping.

That being said from [http://elasticsearch-py.readthedocs.io/en/master/helpers.html](http://elasticsearch-py.readthedocs.io/en/master/helpers.html) "This helper doesn’t transfer mappings, just the data."

Any idea how I can do this?  
Thanks.

---

<div class="post-metadata">

**Author:** ![Glen\_Smith](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/glen_smith/32/111656_2.png) [@Glen\_Smith](https://discuss.elastic.co/u/Glen_Smith)\
**Post date:** [May 26, 2016, 6:38am UTC](https://discuss.elastic.co/t/how-to-change-mapping-and-reindex-to-new-index-using-mapping-with-python-elasticsearch-client-api/51015/2 "2016-05-26T06:38:31Z")

</div>

If you created the new index with a mapping for a specific type, the index kept it. If you indexed to that index and that type, then that mapping was applied.

What are you seeing that leads you to believe the mapping wasn't kept? Are you able to retrieve it and inspect it after creating new-index?

---

<div class="post-metadata">

**Author:** ![timogoosen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timogoosen/32/29750_2.png) [@timogoosen](https://discuss.elastic.co/u/timogoosen)\
**Post date:** [May 26, 2016, 7:41am UTC](https://discuss.elastic.co/t/how-to-change-mapping-and-reindex-to-new-index-using-mapping-with-python-elasticsearch-client-api/51015/3 "2016-05-26T07:41:16Z")

</div>

I created an index "new-index" with a mapping already set and then reindexed from old-index using:

`elasticsearch.helpers.reindex(es, "old-index", "new-index")`

but when I have a look at the mapping of new-index in Sense , then it has the mapping of the old index.  
Not sure what I'm doing wrong.

---

<div class="post-metadata">

**Author:** ![timogoosen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timogoosen/32/29750_2.png) [@timogoosen](https://discuss.elastic.co/u/timogoosen)\
**Post date:** [May 26, 2016, 8:20am UTC](https://discuss.elastic.co/t/how-to-change-mapping-and-reindex-to-new-index-using-mapping-with-python-elasticsearch-client-api/51015/4 "2016-05-26T08:20:42Z")

</div>

Related thread: [https://groups.google.com/forum/?utm\_medium=email&utm\_source=footer#!msg/elasticsearch/1pquAkRyYrI/Qmi6T8t5vLMJ](https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/elasticsearch/1pquAkRyYrI/Qmi6T8t5vLMJ)

Seems like the reindex method can't do this.

---

<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:** [July 5, 2017, 10:48pm UTC](https://discuss.elastic.co/t/how-to-change-mapping-and-reindex-to-new-index-using-mapping-with-python-elasticsearch-client-api/51015/5 "2017-07-05T22:48:54Z")

</div>


