# How to update a mapping?

**URL:** <https://discuss.elastic.co/t/how-to-update-a-mapping/6567>\
**Category:** Elasticsearch\
**Created:** [February 1, 2012, 9:16pm UTC](https://discuss.elastic.co/t/how-to-update-a-mapping/6567 "2012-02-01T21:16:58Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frank\_LaRosa](https://avatars.discourse-cdn.com/v4/letter/f/bc8723/32.png) [@Frank\_LaRosa](https://discuss.elastic.co/u/Frank_LaRosa)\
**Post date:** [February 1, 2012, 9:16pm UTC](https://discuss.elastic.co/t/how-to-update-a-mapping/6567/1 "2012-02-01T21:16:58Z")

</div>

Hi,

I created an index with a mapping, in Java, using the  
IndicesAdminClient.create call with a CreateIndexRequest.

I added a large amount of data to my index.

Now I want to alter the mapping: I wish to add some new fields, and I  
also want to change the index property of one of the existing fields.

How do I accomplish this in Java? Is there a specific call to update a  
mapping, or should I just re-issue the create command with the new  
mapping? Will this destroy any of my old data?

I realize that I will need to update all my documents, and I am  
prepared to do this, but I do not want to have to remove them all  
first.

Thanks.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 1, 2012, 10:39pm UTC](https://discuss.elastic.co/t/how-to-update-a-mapping/6567/2 "2012-02-01T22:39:23Z")

</div>

You can not update the mapping definition for an existing field.  
So you will have to create a new mapping and reindex your docs.

I don't know if you can merge mappings in Java...

David.

Le 1 février 2012 à 22:16, Frank LaRosa [frank@studyblue.com](mailto:frank@studyblue.com) a écrit :

> Hi,
> 
> I created an index with a mapping, in Java, using the  
> IndicesAdminClient.create call with a CreateIndexRequest.
> 
> I added a large amount of data to my index.
> 
> Now I want to alter the mapping: I wish to add some new fields, and I  
> also want to change the index property of one of the existing fields.
> 
> How do I accomplish this in Java? Is there a specific call to update a  
> mapping, or should I just re-issue the create command with the new  
> mapping? Will this destroy any of my old data?
> 
> I realize that I will need to update all my documents, and I am  
> prepared to do this, but I do not want to have to remove them all  
> first.
> 
> Thanks.

--  
David Pilato  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet

---

<div class="post-metadata">

**Author:** ![alichi](https://avatars.discourse-cdn.com/v4/letter/a/bc79bd/32.png) [@alichi](https://discuss.elastic.co/u/alichi)\
**Post date:** [February 1, 2012, 10:44pm UTC](https://discuss.elastic.co/t/how-to-update-a-mapping/6567/3 "2012-02-01T22:44:46Z")

</div>

You can add extra fields to an existing mapping, here is the code (you  
can set ignore conflicts to true if you want to):

new  
PutMappingRequestBuilder(client.admin().indices()).setIgnoreConflicts(true).setIndices(index).setType(type).setSource(mapping).execute().actionGet();

Ali

On Feb 1, 2:39 pm, "[da...@pilato.fr](mailto:da...@pilato.fr)" [da...@pilato.fr](mailto:da...@pilato.fr) wrote:

> You can not update the mapping definition for an existing field.  
> So you will have to create a new mapping and reindex your docs.
> 
> I don't know if you can merge mappings in Java...
> 
> David.
> 
> Le 1 février 2012 à 22:16, Frank LaRosa [fr...@studyblue.com](mailto:fr...@studyblue.com) a écrit :
> 
> > Hi,
> 
> > I created an index with a mapping, in Java, using the  
> > IndicesAdminClient.create call with a CreateIndexRequest.
> 
> > I added a large amount of data to my index.
> 
> > Now I want to alter the mapping: I wish to add some new fields, and I  
> > also want to change the index property of one of the existing fields.
> 
> > How do I accomplish this in Java? Is there a specific call to update a  
> > mapping, or should I just re-issue the create command with the new  
> > mapping? Will this destroy any of my old data?
> 
> > I realize that I will need to update all my documents, and I am  
> > prepared to do this, but I do not want to have to remove them all  
> > first.
> 
> > Thanks.
> 
> --  
> David Pilatohttp://dev.david.pilato.fr/  
> Twitter : @dadoonet

---

<div class="post-metadata">

**Author:** ![Frank\_LaRosa](https://avatars.discourse-cdn.com/v4/letter/f/bc8723/32.png) [@Frank\_LaRosa](https://discuss.elastic.co/u/Frank_LaRosa)\
**Post date:** [February 1, 2012, 10:51pm UTC](https://discuss.elastic.co/t/how-to-update-a-mapping/6567/4 "2012-02-01T22:51:20Z")

</div>

Thanks for the reply.

The code is complaining if I fail to set the Type. I don't know what  
to do:

(1) When I originally created the Index, I did not have to specify a  
type.  
(2) The "setType" function accepts a string rather than an enum, so I  
have no idea what the valid types are or which one I want.

On Feb 1, 4:44 pm, Ali Loghmani [loghm...@gmail.com](mailto:loghm...@gmail.com) wrote:

> You can add extra fields to an existing mapping, here is the code (you  
> can set ignore conflicts to true if you want to):
> 
> new  
> PutMappingRequestBuilder(client.admin().indices()).setIgnoreConflicts(true) .setIndices(index).setType(type).setSource(mapping).execute().actionGet();
> 
> Ali
> 
> On Feb 1, 2:39 pm, "[da...@pilato.fr](mailto:da...@pilato.fr)" [da...@pilato.fr](mailto:da...@pilato.fr) wrote:
> 
> > You can not update the mapping definition for an existing field.  
> > So you will have to create a new mapping and reindex your docs.
> 
> > I don't know if you can merge mappings in Java...
> 
> > David.
> 
> > Le 1 février 2012 à 22:16, Frank LaRosa [fr...@studyblue.com](mailto:fr...@studyblue.com) a écrit :
> 
> > > Hi,
> 
> > > I created an index with a mapping, in Java, using the  
> > > IndicesAdminClient.create call with a CreateIndexRequest.
> 
> > > I added a large amount of data to my index.
> 
> > > Now I want to alter the mapping: I wish to add some new fields, and I  
> > > also want to change the index property of one of the existing fields.
> 
> > > How do I accomplish this in Java? Is there a specific call to update a  
> > > mapping, or should I just re-issue the create command with the new  
> > > mapping? Will this destroy any of my old data?
> 
> > > I realize that I will need to update all my documents, and I am  
> > > prepared to do this, but I do not want to have to remove them all  
> > > first.
> 
> > > Thanks.
> 
> > --  
> > David Pilatohttp://dev.david.pilato.fr/  
> > Twitter : @dadoonet

---

<div class="post-metadata">

**Author:** ![Frank\_LaRosa](https://avatars.discourse-cdn.com/v4/letter/f/bc8723/32.png) [@Frank\_LaRosa](https://discuss.elastic.co/u/Frank_LaRosa)\
**Post date:** [February 1, 2012, 11:02pm UTC](https://discuss.elastic.co/t/how-to-update-a-mapping/6567/5 "2012-02-01T23:02:06Z")

</div>

I don't want it to automatically reindex all the documents for me. I  
just want to update the mapping definition for when I add new  
documents.

On Feb 1, 4:39 pm, "[da...@pilato.fr](mailto:da...@pilato.fr)" [da...@pilato.fr](mailto:da...@pilato.fr) wrote:

> You can not update the mapping definition for an existing field.  
> So you will have to create a new mapping and reindex your docs.
> 
> I don't know if you can merge mappings in Java...
> 
> David.
> 
> Le 1 février 2012 à 22:16, Frank LaRosa [fr...@studyblue.com](mailto:fr...@studyblue.com) a écrit :
> 
> > Hi,
> 
> > I created an index with a mapping, in Java, using the  
> > IndicesAdminClient.create call with a CreateIndexRequest.
> 
> > I added a large amount of data to my index.
> 
> > Now I want to alter the mapping: I wish to add some new fields, and I  
> > also want to change the index property of one of the existing fields.
> 
> > How do I accomplish this in Java? Is there a specific call to update a  
> > mapping, or should I just re-issue the create command with the new  
> > mapping? Will this destroy any of my old data?
> 
> > I realize that I will need to update all my documents, and I am  
> > prepared to do this, but I do not want to have to remove them all  
> > first.
> 
> > Thanks.
> 
> --  
> David Pilatohttp://dev.david.pilato.fr/  
> Twitter : @dadoonet

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 2, 2012, 6:08am UTC](https://discuss.elastic.co/t/how-to-update-a-mapping/6567/6 "2012-02-02T06:08:29Z")

</div>

Yes but if you want to modify an existing field (e.g. You want to add an analyzer), you won't be able to do it.  
But if you only add new fields, it will work.

David 😉  
@dadoonet

Le 2 févr. 2012 à 00:02, Frank LaRosa [frank@studyblue.com](mailto:frank@studyblue.com) a écrit :

> I don't want it to automatically reindex all the documents for me. I  
> just want to update the mapping definition for when I add new  
> documents.
> 
> On Feb 1, 4:39 pm, "[da...@pilato.fr](mailto:da...@pilato.fr)" [da...@pilato.fr](mailto:da...@pilato.fr) wrote:
> 
> > You can not update the mapping definition for an existing field.  
> > So you will have to create a new mapping and reindex your docs.
> > 
> > I don't know if you can merge mappings in Java...
> > 
> > David.
> > 
> > Le 1 février 2012 à 22:16, Frank LaRosa [fr...@studyblue.com](mailto:fr...@studyblue.com) a écrit :
> > 
> > > Hi,
> > 
> > > I created an index with a mapping, in Java, using the  
> > > IndicesAdminClient.create call with a CreateIndexRequest.
> > 
> > > I added a large amount of data to my index.
> > 
> > > Now I want to alter the mapping: I wish to add some new fields, and I  
> > > also want to change the index property of one of the existing fields.
> > 
> > > How do I accomplish this in Java? Is there a specific call to update a  
> > > mapping, or should I just re-issue the create command with the new  
> > > mapping? Will this destroy any of my old data?
> > 
> > > I realize that I will need to update all my documents, and I am  
> > > prepared to do this, but I do not want to have to remove them all  
> > > first.
> > 
> > > Thanks.
> > 
> > --  
> > David Pilatohttp://dev.david.pilato.fr/  
> > Twitter : @dadoonet

---

<div class="post-metadata">

**Author:** ![Frank\_LaRosa](https://avatars.discourse-cdn.com/v4/letter/f/bc8723/32.png) [@Frank\_LaRosa](https://discuss.elastic.co/u/Frank_LaRosa)\
**Post date:** [February 2, 2012, 5:08pm UTC](https://discuss.elastic.co/t/how-to-update-a-mapping/6567/7 "2012-02-02T17:08:54Z")

</div>

I was able to modify a field and change the index value on a field  
from "no" to "not analyzed". At least, the server accepted the request  
without throwing any exception. I won't know for sure if it actually  
worked.

As an aside, I have a large index that took almost a week to build. It  
isn't practical for me to delete it and reindex. I hope that the  
developers of Elasticsearch keep people like me in mind as they  
develop the product, and do not expect us to simply start over  
whenever we want to make changes to our data stores.

On Feb 2, 12:08 am, David Pilato [da...@pilato.fr](mailto:da...@pilato.fr) wrote:

> Yes but if you want to modify an existing field (e.g. You want to add an analyzer), you won't be able to do it.  
> But if you only add new fields, it will work.
> 
> David 😉  
> @dadoonet
> 
> Le 2 févr. 2012 à 00:02, Frank LaRosa [fr...@studyblue.com](mailto:fr...@studyblue.com) a écrit :
> 
> > I don't want it to automatically reindex all the documents for me. I  
> > just want to update the mapping definition for when I add new  
> > documents.
> 
> > On Feb 1, 4:39 pm, "[da...@pilato.fr](mailto:da...@pilato.fr)" [da...@pilato.fr](mailto:da...@pilato.fr) wrote:
> > 
> > > You can not update the mapping definition for an existing field.  
> > > So you will have to create a new mapping and reindex your docs.
> 
> > > I don't know if you can merge mappings in Java...
> 
> > > David.
> 
> > > Le 1 février 2012 à 22:16, Frank LaRosa [fr...@studyblue.com](mailto:fr...@studyblue.com) a écrit :
> 
> > > > Hi,
> 
> > > > I created an index with a mapping, in Java, using the  
> > > > IndicesAdminClient.create call with a CreateIndexRequest.
> 
> > > > I added a large amount of data to my index.
> 
> > > > Now I want to alter the mapping: I wish to add some new fields, and I  
> > > > also want to change the index property of one of the existing fields.
> 
> > > > How do I accomplish this in Java? Is there a specific call to update a  
> > > > mapping, or should I just re-issue the create command with the new  
> > > > mapping? Will this destroy any of my old data?
> 
> > > > I realize that I will need to update all my documents, and I am  
> > > > prepared to do this, but I do not want to have to remove them all  
> > > > first.
> 
> > > > Thanks.
> 
> > > --  
> > > David Pilatohttp://dev.david.pilato.fr/  
> > > Twitter : @dadoonet

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [February 5, 2012, 11:22am UTC](https://discuss.elastic.co/t/how-to-update-a-mapping/6567/8 "2012-02-05T11:22:28Z")

</div>

You can verify if you mapping has been updated or not by using get mapping. Some aspects can be changed, but not the "index" aspect of a field.

On Thursday, February 2, 2012 at 7:08 PM, Frank LaRosa wrote:

> I was able to modify a field and change the index value on a field  
> from "no" to "not analyzed". At least, the server accepted the request  
> without throwing any exception. I won't know for sure if it actually  
> worked.
> 
> As an aside, I have a large index that took almost a week to build. It  
> isn't practical for me to delete it and reindex. I hope that the  
> developers of Elasticsearch keep people like me in mind as they  
> develop the product, and do not expect us to simply start over  
> whenever we want to make changes to our data stores.
> 
> On Feb 2, 12:08 am, David Pilato \<[da...@pilato.fr](mailto:da...@pilato.fr) ([http://pilato.fr](http://pilato.fr))\> wrote:
> 
> > Yes but if you want to modify an existing field (e.g. You want to add an analyzer), you won't be able to do it.  
> > But if you only add new fields, it will work.
> > 
> > David 😉  
> > @dadoonet
> > 
> > Le 2 févr. 2012 à 00:02, Frank LaRosa \<[fr...@studyblue.com](mailto:fr...@studyblue.com) ([http://studyblue.com](http://studyblue.com))\> a écrit :
> > 
> > > I don't want it to automatically reindex all the documents for me. I  
> > > just want to update the mapping definition for when I add new  
> > > documents.
> > 
> > > On Feb 1, 4:39 pm, "[da...@pilato.fr](mailto:da...@pilato.fr) ([http://pilato.fr](http://pilato.fr))" \<[da...@pilato.fr](mailto:da...@pilato.fr) ([http://pilato.fr](http://pilato.fr))\> wrote:
> > > 
> > > > You can not update the mapping definition for an existing field.  
> > > > So you will have to create a new mapping and reindex your docs.
> > 
> > > > I don't know if you can merge mappings in Java...
> > 
> > > > David.
> > 
> > > > Le 1 février 2012 à 22:16, Frank LaRosa \<[fr...@studyblue.com](mailto:fr...@studyblue.com) ([http://studyblue.com](http://studyblue.com))\> a écrit :
> > 
> > > > > Hi,
> > 
> > > > > I created an index with a mapping, in Java, using the  
> > > > > IndicesAdminClient.create call with a CreateIndexRequest.
> > 
> > > > > I added a large amount of data to my index.
> > 
> > > > > Now I want to alter the mapping: I wish to add some new fields, and I  
> > > > > also want to change the index property of one of the existing fields.
> > 
> > > > > How do I accomplish this in Java? Is there a specific call to update a  
> > > > > mapping, or should I just re-issue the create command with the new  
> > > > > mapping? Will this destroy any of my old data?
> > 
> > > > > I realize that I will need to update all my documents, and I am  
> > > > > prepared to do this, but I do not want to have to remove them all  
> > > > > first.
> > 
> > > > > Thanks.
> > 
> > > > --  
> > > > David Pilatohttp://dev.david.pilato.fr/  
> > > > Twitter : @dadoonet

---

<div class="post-metadata">

**Author:** ![ajasuja18](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@ajasuja18](https://discuss.elastic.co/u/ajasuja18)\
**Post date:** [August 11, 2012, 12:16am UTC](https://discuss.elastic.co/t/how-to-update-a-mapping/6567/9 "2012-08-11T00:16:29Z")

</div>

Hi Ali,

Can you tell me how to do ignore\_conflicts without using java api?

Also any insight on what will happen if I make ignore\_conflicts:true?  
For example: will my mapping have the same field name with two  
different types if I change the type of one of my field? Also if now my data  
have that field, then what type(out of those 2) will ES use to index the  
new data?

Thanks in advance..!!!

ankit

On Wednesday, February 1, 2012 2:44:46 PM UTC-8, Ali Loghmani wrote:

> You can add extra fields to an existing mapping, here is the code (you  
> can set ignore conflicts to true if you want to):
> 
> new  
> PutMappingRequestBuilder(client.admin().indices()).setIgnoreConflicts(true).setIndices(index).setType(type).setSource(mapping).execute().actionGet();
> 
> Ali
> 
> On Feb 1, 2:39 pm, "[da...@pilato.fr](mailto:da...@pilato.fr)" [da...@pilato.fr](mailto:da...@pilato.fr) wrote:
> 
> > You can not update the mapping definition for an existing field.  
> > So you will have to create a new mapping and reindex your docs.
> > 
> > I don't know if you can merge mappings in Java...
> > 
> > David.
> > 
> > Le 1 février 2012 à 22:16, Frank LaRosa [fr...@studyblue.com](mailto:fr...@studyblue.com) a écrit :
> > 
> > > Hi,
> > 
> > > I created an index with a mapping, in Java, using the  
> > > IndicesAdminClient.create call with a CreateIndexRequest.
> > 
> > > I added a large amount of data to my index.
> > 
> > > Now I want to alter the mapping: I wish to add some new fields, and I  
> > > also want to change the index property of one of the existing fields.
> > 
> > > How do I accomplish this in Java? Is there a specific call to update a  
> > > mapping, or should I just re-issue the create command with the new  
> > > mapping? Will this destroy any of my old data?
> > 
> > > I realize that I will need to update all my documents, and I am  
> > > prepared to do this, but I do not want to have to remove them all  
> > > first.
> > 
> > > Thanks.
> > 
> > --  
> > David Pilatohttp://dev.david.pilato.fr/  
> > Twitter : @dadoonet

--

---

<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 6, 2017, 3:16am UTC](https://discuss.elastic.co/t/how-to-update-a-mapping/6567/10 "2017-07-06T03:16:43Z")

</div>


