# Elasticsearch Java API prepareIndex overwrites existing mapping

**URL:** https://discuss.elastic.co/t/elasticsearch-java-api-prepareindex-overwrites-existing-mapping/17219
**Category:** Elasticsearch
**Created:** [April 27, 2014, 7:45am UTC](https://discuss.elastic.co/t/elasticsearch-java-api-prepareindex-overwrites-existing-mapping/17219 "2014-04-27T07:45:08Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Hosang\_Jeon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hosang_jeon/32/1020_2.png) [@Hosang\_Jeon](https://discuss.elastic.co/u/Hosang_Jeon)
#### Post date: [April 27, 2014, 7:45am UTC](https://discuss.elastic.co/t/elasticsearch-java-api-prepareindex-overwrites-existing-mapping/17219/1 "2014-04-27T07:45:08Z")

</div>

I'm in trouble with the overwriting action of prepareIndex method in  
Elasticsearch Java API.

The problem is that my _mapping definition has changed after new document  
has indexed._

First of all, I defined an mapping to set "not\_analyzed" index for a  
particular field.

String json = myMethodToGetMapping();  
PutMappingResponse pmrs = client.admin().indices().preparePutMapping(  
"my\_index").setType("my\_type").setSource(json).setIgnoreConflicts(true).  
execute().actionGet();

if (pmrs == null || !pmrs.isAcknowledged()) {  
System.out.println("Put Mapping Failure.");  
} else {  
System.out.println("Put Mapping Success.");  
}

In my mapping string(json), there is a field has settings like below.

"myFieldExact":{  
"type":"string",  
"index": "not\_analyzed",  
"dynamic": false  
}

After the code has executed, I could see the proper mapping which I want to  
get.

curl -XGET http://{my\_ip\_address}:9200/my\_index/my\_type/\_mapping/

{"my\_type":{"properties":{........ "myFieldExact":{"type":"string","index":  
"not\_analyzed","omit\_norms":true,"index\_options":"docs"},...... }}}

_HOWEVER_, this mapping has been changed after I put some data using Java  
API prepareIndex.

MyObject myObject = new MyObject();  
myObject.setMyFieldExact("some-value");  
String json = new org.codehaus.jackson.map.ObjectMapper().writeValueAsString  
(myObject);  
client.prepareIndex("my\_index", "my\_type", "my\_id")  
.setSource(json).execute().actionGet();

The document successfully indexed into "my\_index/my\_type/my\_id".

Here is the problem I have.

After the new record has been indexed, the original mapping definition has  
changed like below.

curl -XGET http://{my\_ip\_address}:9200/my\_index/my\_type/\_mapping/

{"my\_type":{"properties":{........ "myFieldExact":{"type":"string"},......  
}}}

In short, the _"index":"not\_analyzed" property has been gone after the new  
document has indexed._

Is there anyone can help me?

Thank you very much in advance.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5ee40a83-272b-4843-ba6f-f79b78737942%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5ee40a83-272b-4843-ba6f-f79b78737942%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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: [April 27, 2014, 8:52am UTC](https://discuss.elastic.co/t/elasticsearch-java-api-prepareindex-overwrites-existing-mapping/17219/2 "2014-04-27T08:52:03Z")

</div>

Probably your first mapping is incorrect or applied to another type or index.

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

> Le 27 avr. 2014 à 09:45, Ho-sang Jeon [jhsbeat@gmail.com](mailto:jhsbeat@gmail.com) a écrit :
> 
> I'm in trouble with the overwriting action of prepareIndex method in Elasticsearch Java API.
> 
> The problem is that my mapping definition has changed after new document has indexed.
> 
> First of all, I defined an mapping to set "not\_analyzed" index for a particular field.
> 
> String json = myMethodToGetMapping();  
> PutMappingResponse pmrs = client.admin().indices().preparePutMapping("my\_index").setType("my\_type").setSource(json).setIgnoreConflicts(true).execute().actionGet();
> 
> if (pmrs == null || !pmrs.isAcknowledged()) {  
> System.out.println("Put Mapping Failure.");  
> } else {  
> System.out.println("Put Mapping Success.");  
> }
> 
> In my mapping string(json), there is a field has settings like below.
> 
> "myFieldExact":{  
> "type":"string",  
> "index": "not\_analyzed",  
> "dynamic": false  
> }
> 
> After the code has executed, I could see the proper mapping which I want to get.
> 
> curl -XGET http://{my\_ip\_address}:9200/my\_index/my\_type/\_mapping/
> 
> {"my\_type":{"properties":{........ "myFieldExact":{"type":"string","index":"not\_analyzed","omit\_norms":true,"index\_options":"docs"},...... }}}
> 
> HOWEVER, this mapping has been changed after I put some data using Java API prepareIndex.
> 
> MyObject myObject = new MyObject();  
> myObject.setMyFieldExact("some-value");  
> String json = new org.codehaus.jackson.map.ObjectMapper().writeValueAsString(myObject);  
> client.prepareIndex("my\_index", "my\_type", "my\_id")  
> .setSource(json).execute().actionGet();
> 
> The document successfully indexed into "my\_index/my\_type/my\_id".
> 
> Here is the problem I have.
> 
> After the new record has been indexed, the original mapping definition has changed like below.
> 
> curl -XGET http://{my\_ip\_address}:9200/my\_index/my\_type/\_mapping/
> 
> {"my\_type":{"properties":{........ "myFieldExact":{"type":"string"},...... }}}
> 
> In short, the "index":"not\_analyzed" property has been gone after the new document has indexed.
> 
> Is there anyone can help me?
> 
> ## Thank you very much in advance.
> 
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5ee40a83-272b-4843-ba6f-f79b78737942%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5ee40a83-272b-4843-ba6f-f79b78737942%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/62649AA7-B1B3-475B-A2F1-B624991C78BD%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/62649AA7-B1B3-475B-A2F1-B624991C78BD%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Hosang\_Jeon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hosang_jeon/32/1020_2.png) [@Hosang\_Jeon](https://discuss.elastic.co/u/Hosang_Jeon)
#### Post date: [April 27, 2014, 9:18am UTC](https://discuss.elastic.co/t/elasticsearch-java-api-prepareindex-overwrites-existing-mapping/17219/3 "2014-04-27T09:18:13Z")

</div>

Thanks David Pilato.

However, as I mentioned, I could see the correct mappings for the correct  
index and type like below.

curl -XGET http://{my\_ip\_address}:9200/my\_index/my\_type/\_mapping/

{"my\_type":{"properties":{........ "myFieldExact":{"type":"string","index":  
"not\_analyzed","omit\_norms":true,"index\_options":"docs"},...... }}}

After I index a new document into the index I got the changed mapping  
result for the exactly same GET url.

curl -XGET http://{my\_ip\_address}:9200/my\_index/my\_type/\_mapping/

{"my\_type":{"properties":{........ "myFieldExact":{"type":"string"},......  
}}}

On Sunday, April 27, 2014 5:52:03 PM UTC+9, David Pilato wrote:

> Probably your first mapping is incorrect or applied to another type or  
> index.
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 27 avr. 2014 à 09:45, Ho-sang Jeon \<[jhs...@gmail.com](mailto:jhs...@gmail.com) \<javascript:\>\> a  
> écrit :
> 
> I'm in trouble with the overwriting action of prepareIndex method in  
> Elasticsearch Java API.
> 
> The problem is that my _mapping definition has changed after new document  
> has indexed._
> 
> First of all, I defined an mapping to set "not\_analyzed" index for a  
> particular field.
> 
> String json = myMethodToGetMapping();  
> PutMappingResponse pmrs = client.admin().indices().preparePutMapping(  
> "my\_index").setType("my\_type").setSource(json).setIgnoreConflicts(true).  
> execute().actionGet();
> 
> if (pmrs == null || !pmrs.isAcknowledged()) {  
> System.out.println("Put Mapping Failure.");  
> } else {  
> System.out.println("Put Mapping Success.");  
> }
> 
> In my mapping string(json), there is a field has settings like below.
> 
> "myFieldExact":{  
> "type":"string",  
> "index": "not\_analyzed",  
> "dynamic": false  
> }
> 
> After the code has executed, I could see the proper mapping which I want  
> to get.
> 
> curl -XGET http://{my\_ip\_address}:9200/my\_index/my\_type/\_mapping/
> 
> {"my\_type":{"properties":{........ "myFieldExact":{"type":"string","index"  
> :"not\_analyzed","omit\_norms":true,"index\_options":"docs"},...... }}}
> 
> _HOWEVER_, this mapping has been changed after I put some data using Java  
> API prepareIndex.
> 
> MyObject myObject = new MyObject();  
> myObject.setMyFieldExact("some-value");  
> String json = new org.codehaus.jackson.map.ObjectMapper().  
> writeValueAsString(myObject);  
> client.prepareIndex("my\_index", "my\_type", "my\_id")  
> .setSource(json).execute().actionGet();
> 
> The document successfully indexed into "my\_index/my\_type/my\_id".
> 
> Here is the problem I have.
> 
> After the new record has been indexed, the original mapping definition has  
> changed like below.
> 
> curl -XGET http://{my\_ip\_address}:9200/my\_index/my\_type/\_mapping/
> 
> {"my\_type":{"properties":{........ "myFieldExact":{"type":"string"},......  
> }}}
> 
> In short, the _"index":"not\_analyzed" property has been gone after the  
> new document has indexed._
> 
> Is there anyone can help me?
> 
> Thank you very much in advance.
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/5ee40a83-272b-4843-ba6f-f79b78737942%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5ee40a83-272b-4843-ba6f-f79b78737942%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/5ee40a83-272b-4843-ba6f-f79b78737942%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/5ee40a83-272b-4843-ba6f-f79b78737942%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/caf69fb3-2d65-4cf4-9f4c-ca88c959906a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/caf69fb3-2d65-4cf4-9f4c-ca88c959906a%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Hosang\_Jeon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hosang_jeon/32/1020_2.png) [@Hosang\_Jeon](https://discuss.elastic.co/u/Hosang_Jeon)
#### Post date: [April 27, 2014, 9:36am UTC](https://discuss.elastic.co/t/elasticsearch-java-api-prepareindex-overwrites-existing-mapping/17219/4 "2014-04-27T09:36:08Z")

</div>

Thanks David Pilato.

However, as I mentioned, I could see the correct mappings for the correct  
index and type like below.

curl -XGET http://{my\_ip\_address}:9200/my\_index/my\_type/\_mapping/

{"my\_type":{"properties":{........ "myFieldExact":{"type":"string","index":  
"not\_analyzed","omit\_norms":true,"index\_options":"docs"},...... }}}

After I index a new document into the index I got the changed mapping  
result for the exactly same GET url.

curl -XGET http://{my\_ip\_address}:9200/my\_index/my\_type/\_mapping/

{"my\_type":{"properties":{........ "myFieldExact":{"type":"string"},......  
}}}

Here are some more detailed information.

1. I'm using Elasticsearch version 0.90.0.
2. The field "myFieldExact" is actually in an array. The real documents  
seem like below.

myFieldList: [  
{  
myFieldExact: "ABCD-1"  
},  
{  
myFieldExact: "ABCD-2"  
},  
{  
myFieldExact: "ABCD-2"  
}  
]

On Sunday, April 27, 2014 5:52:03 PM UTC+9, David Pilato wrote:

> Probably your first mapping is incorrect or applied to another type or  
> index.
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 27 avr. 2014 à 09:45, Ho-sang Jeon \<[jhs...@gmail.com](mailto:jhs...@gmail.com) \<javascript:\>\> a  
> écrit :
> 
> I'm in trouble with the overwriting action of prepareIndex method in  
> Elasticsearch Java API.
> 
> The problem is that my _mapping definition has changed after new document  
> has indexed._
> 
> First of all, I defined an mapping to set "not\_analyzed" index for a  
> particular field.
> 
> String json = myMethodToGetMapping();  
> PutMappingResponse pmrs = client.admin().indices().preparePutMapping(  
> "my\_index").setType("my\_type").setSource(json).setIgnoreConflicts(true).  
> execute().actionGet();
> 
> if (pmrs == null || !pmrs.isAcknowledged()) {  
> System.out.println("Put Mapping Failure.");  
> } else {  
> System.out.println("Put Mapping Success.");  
> }
> 
> In my mapping string(json), there is a field has settings like below.
> 
> "myFieldExact":{  
> "type":"string",  
> "index": "not\_analyzed",  
> "dynamic": false  
> }
> 
> After the code has executed, I could see the proper mapping which I want  
> to get.
> 
> curl -XGET http://{my\_ip\_address}:9200/my\_index/my\_type/\_mapping/
> 
> {"my\_type":{"properties":{........ "myFieldExact":{"type":"string","index"  
> :"not\_analyzed","omit\_norms":true,"index\_options":"docs"},...... }}}
> 
> _HOWEVER_, this mapping has been changed after I put some data using Java  
> API prepareIndex.
> 
> MyObject myObject = new MyObject();  
> myObject.setMyFieldExact("some-value");  
> String json = new org.codehaus.jackson.map.ObjectMapper().  
> writeValueAsString(myObject);  
> client.prepareIndex("my\_index", "my\_type", "my\_id")  
> .setSource(json).execute().actionGet();
> 
> The document successfully indexed into "my\_index/my\_type/my\_id".
> 
> Here is the problem I have.
> 
> After the new record has been indexed, the original mapping definition has  
> changed like below.
> 
> curl -XGET http://{my\_ip\_address}:9200/my\_index/my\_type/\_mapping/
> 
> {"my\_type":{"properties":{........ "myFieldExact":{"type":"string"},......  
> }}}
> 
> In short, the _"index":"not\_analyzed" property has been gone after the  
> new document has indexed._
> 
> Is there anyone can help me?
> 
> Thank you very much in advance.
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/5ee40a83-272b-4843-ba6f-f79b78737942%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5ee40a83-272b-4843-ba6f-f79b78737942%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/5ee40a83-272b-4843-ba6f-f79b78737942%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/5ee40a83-272b-4843-ba6f-f79b78737942%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/fb95c354-b1ad-4920-940d-e678d430e9fc%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fb95c354-b1ad-4920-940d-e678d430e9fc%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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: [April 27, 2014, 9:51am UTC](https://discuss.elastic.co/t/elasticsearch-java-api-prepareindex-overwrites-existing-mapping/17219/5 "2014-04-27T09:51:00Z")

</div>

I think you are pasting here your actual data.

So it's hard to tell where you are doing something wrong.

May be you could GIST a full curl/SENSE recreation?

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

> Le 27 avr. 2014 à 11:36, Ho-sang Jeon [jhsbeat@gmail.com](mailto:jhsbeat@gmail.com) a écrit :
> 
> Thanks David Pilato.
> 
> However, as I mentioned, I could see the correct mappings for the correct index and type like below.
> 
> curl -XGET http://{my\_ip\_address}:9200/my\_index/my\_type/\_mapping/
> 
> {"my\_type":{"properties":{........ "myFieldExact":{"type":"string","index":"not\_analyzed","omit\_norms":true,"index\_options":"docs"},...... }}}
> 
> After I index a new document into the index I got the changed mapping result for the exactly same GET url.
> 
> curl -XGET http://{my\_ip\_address}:9200/my\_index/my\_type/\_mapping/
> 
> {"my\_type":{"properties":{........ "myFieldExact":{"type":"string"},...... }}}
> 
> Here are some more detailed information.  
> I'm using Elasticsearch version 0.90.0.  
> The field "myFieldExact" is actually in an array. The real documents seem like below.
> 
> myFieldList: [  
> {  
> myFieldExact: "ABCD-1"  
> },  
> {  
> myFieldExact: "ABCD-2"  
> },  
> {  
> myFieldExact: "ABCD-2"  
> }  
> ]
> 
> > On Sunday, April 27, 2014 5:52:03 PM UTC+9, David Pilato wrote:  
> > Probably your first mapping is incorrect or applied to another type or index.
> > 
> > --  
> > David 😉  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > 
> > > Le 27 avr. 2014 à 09:45, Ho-sang Jeon [jhs...@gmail.com](mailto:jhs...@gmail.com) a écrit :
> > > 
> > > I'm in trouble with the overwriting action of prepareIndex method in Elasticsearch Java API.
> > > 
> > > The problem is that my mapping definition has changed after new document has indexed.
> > > 
> > > First of all, I defined an mapping to set "not\_analyzed" index for a particular field.
> > > 
> > > String json = myMethodToGetMapping();  
> > > PutMappingResponse pmrs = client.admin().indices().preparePutMapping("my\_index").setType("my\_type").setSource(json).setIgnoreConflicts(true).execute().actionGet();
> > > 
> > > if (pmrs == null || !pmrs.isAcknowledged()) {  
> > > System.out.println("Put Mapping Failure.");  
> > > } else {  
> > > System.out.println("Put Mapping Success.");  
> > > }
> > > 
> > > In my mapping string(json), there is a field has settings like below.
> > > 
> > > "myFieldExact":{  
> > > "type":"string",  
> > > "index": "not\_analyzed",  
> > > "dynamic": false  
> > > }
> > > 
> > > After the code has executed, I could see the proper mapping which I want to get.
> > > 
> > > curl -XGET http://{my\_ip\_address}:9200/my\_index/my\_type/\_mapping/
> > > 
> > > {"my\_type":{"properties":{........ "myFieldExact":{"type":"string","index":"not\_analyzed","omit\_norms":true,"index\_options":"docs"},...... }}}
> > > 
> > > HOWEVER, this mapping has been changed after I put some data using Java API prepareIndex.
> > > 
> > > MyObject myObject = new MyObject();  
> > > myObject.setMyFieldExact("some-value");  
> > > String json = new org.codehaus.jackson.map.ObjectMapper().writeValueAsString(myObject);  
> > > client.prepareIndex("my\_index", "my\_type", "my\_id")  
> > > .setSource(json).execute().actionGet();
> > > 
> > > The document successfully indexed into "my\_index/my\_type/my\_id".
> > > 
> > > Here is the problem I have.
> > > 
> > > After the new record has been indexed, the original mapping definition has changed like below.
> > > 
> > > curl -XGET http://{my\_ip\_address}:9200/my\_index/my\_type/\_mapping/
> > > 
> > > {"my\_type":{"properties":{........ "myFieldExact":{"type":"string"},...... }}}
> > > 
> > > In short, the "index":"not\_analyzed" property has been gone after the new document has indexed.
> > > 
> > > Is there anyone can help me?
> > > 
> > > ## Thank you very much in advance.
> > > 
> > > You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5ee40a83-272b-4843-ba6f-f79b78737942%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5ee40a83-272b-4843-ba6f-f79b78737942%40googlegroups.com).  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/fb95c354-b1ad-4920-940d-e678d430e9fc%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fb95c354-b1ad-4920-940d-e678d430e9fc%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/F802AAA5-AAD9-4EC4-9CB1-4929EB87DE79%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/F802AAA5-AAD9-4EC4-9CB1-4929EB87DE79%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Hosang\_Jeon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hosang_jeon/32/1020_2.png) [@Hosang\_Jeon](https://discuss.elastic.co/u/Hosang_Jeon)
#### Post date: [April 27, 2014, 10:49am UTC](https://discuss.elastic.co/t/elasticsearch-java-api-prepareindex-overwrites-existing-mapping/17219/6 "2014-04-27T10:49:06Z")

</div>

Thank you very much David Pilato.

OK. Here is my GIST [Elasticsearch overwriting mapping problem GIST · GitHub](https://gist.github.com/jhsbeat/11342294)

In GistTest.java, after I exectued "testPutMappingTemplate()" method, I can  
get the mapping below.

{"my\_type":{"properties":{"dataId":{"type":"long"},"myFieldList":{"properties":{"myFieldExact":{"type":"string","index":"not\_analyzed","omit\_norms":true,"index\_options":"docs"}}}}}}

However, after I ran "testIndexNewObject()" method, I got the mapping below.

{"my\_type":{"properties":{"dataId":{"type":"long"},"myFieldList":{"properties":{"myFieldExact":{"type":"string"}}}}}}

Do I have to remove my whole index and recreate it?

On Sunday, April 27, 2014 6:51:00 PM UTC+9, David Pilato wrote:

> I think you are pasting here your actual data.
> 
> So it's hard to tell where you are doing something wrong.
> 
> May be you could GIST a full curl/SENSE recreation?
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 27 avr. 2014 à 11:36, Ho-sang Jeon \<[jhs...@gmail.com](mailto:jhs...@gmail.com) \<javascript:\>\> a  
> écrit :
> 
> Thanks David Pilato.
> 
> However, as I mentioned, I could see the correct mappings for the correct  
> index and type like below.
> 
> curl -XGET http://{my\_ip\_address}:9200/my\_index/my\_type/\_mapping/
> 
> {"my\_type":{"properties":{........ "myFieldExact":{"type":"string","index"  
> :"not\_analyzed","omit\_norms":true,"index\_options":"docs"},...... }}}
> 
> After I index a new document into the index I got the changed mapping  
> result for the exactly same GET url.
> 
> curl -XGET http://{my\_ip\_address}:9200/my\_index/my\_type/\_mapping/
> 
> {"my\_type":{"properties":{........ "myFieldExact":{"type":"string"},......  
> }}}
> 
> Here are some more detailed information.
> 
> 1. I'm using Elasticsearch version 0.90.0.
> 2. The field "myFieldExact" is actually in an array. The real  
> documents seem like below.
> 
> myFieldList: [  
> {  
> myFieldExact: "ABCD-1"  
> },  
> {  
> myFieldExact: "ABCD-2"  
> },  
> {  
> myFieldExact: "ABCD-2"  
> }  
> ]
> 
> On Sunday, April 27, 2014 5:52:03 PM UTC+9, David Pilato wrote:
> 
> > Probably your first mapping is incorrect or applied to another type or  
> > index.
> > 
> > --  
> > David 😉  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > 
> > Le 27 avr. 2014 à 09:45, Ho-sang Jeon [jhs...@gmail.com](mailto:jhs...@gmail.com) a écrit :
> > 
> > I'm in trouble with the overwriting action of prepareIndex method in  
> > Elasticsearch Java API.
> > 
> > The problem is that my _mapping definition has changed after new  
> > document has indexed._
> > 
> > First of all, I defined an mapping to set "not\_analyzed" index for a  
> > particular field.
> > 
> > String json = myMethodToGetMapping();  
> > PutMappingResponse pmrs = client.admin().indices().preparePutMapping(  
> > "my\_index").setType("my\_type").setSource(json).setIgnoreConflicts(true).  
> > execute().actionGet();
> > 
> > if (pmrs == null || !pmrs.isAcknowledged()) {  
> > System.out.println("Put Mapping Failure.");  
> > } else {  
> > System.out.println("Put Mapping Success.");  
> > }
> > 
> > In my mapping string(json), there is a field has settings like below.
> > 
> > "myFieldExact":{  
> > "type":"string",  
> > "index": "not\_analyzed",  
> > "dynamic": false  
> > }
> > 
> > After the code has executed, I could see the proper mapping which I want  
> > to get.
> > 
> > curl -XGET http://{my\_ip\_address}:9200/my\_index/my\_type/\_mapping/
> > 
> > {"my\_type":{"properties":{........ "myFieldExact":{"type":"string",  
> > "index":"not\_analyzed","omit\_norms":true,"index\_options":"docs"},......  
> > }}}
> > 
> > _HOWEVER_, this mapping has been changed after I put some data using  
> > Java API prepareIndex.
> > 
> > MyObject myObject = new MyObject();  
> > myObject.setMyFieldExact("some-value");  
> > String json = new org.codehaus.jackson.map.ObjectMapper().  
> > writeValueAsString(myObject);  
> > client.prepareIndex("my\_index", "my\_type", "my\_id")  
> > .setSource(json).execute().actionGet();
> > 
> > The document successfully indexed into "my\_index/my\_type/my\_id".
> > 
> > Here is the problem I have.
> > 
> > After the new record has been indexed, the original mapping definition  
> > has changed like below.
> > 
> > curl -XGET http://{my\_ip\_address}:9200/my\_index/my\_type/\_mapping/
> > 
> > {"my\_type":{"properties":{........ "myFieldExact":{"type":"string"  
> > },...... }}}
> > 
> > In short, the _"index":"not\_analyzed" property has been gone after the  
> > new document has indexed._
> > 
> > Is there anyone can help me?
> > 
> > Thank you very much in advance.
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/5ee40a83-272b-4843-ba6f-f79b78737942%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5ee40a83-272b-4843-ba6f-f79b78737942%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/5ee40a83-272b-4843-ba6f-f79b78737942%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/5ee40a83-272b-4843-ba6f-f79b78737942%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/fb95c354-b1ad-4920-940d-e678d430e9fc%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fb95c354-b1ad-4920-940d-e678d430e9fc%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/fb95c354-b1ad-4920-940d-e678d430e9fc%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/fb95c354-b1ad-4920-940d-e678d430e9fc%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/e9099a04-6b73-4eb0-b43a-dbc836067005%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e9099a04-6b73-4eb0-b43a-dbc836067005%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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: [April 28, 2014, 9:09pm UTC](https://discuss.elastic.co/t/elasticsearch-java-api-prepareindex-overwrites-existing-mapping/17219/7 "2014-04-28T21:09:54Z")

</div>

From a 10.000 feet point of view, your code looks good to me.

The only for mapping to change as you described is that type has been removed between the two run.

I don't see any other explanation.

What can you see in elasticsearch node logs? Before the first test, after the first test and after the second test?

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

Le 27 avril 2014 à 12:49:10, Ho-sang Jeon ([jhsbeat@gmail.com](mailto:jhsbeat@gmail.com)) a écrit:

Thank you very much David Pilato.

OK. Here is my GIST [https://gist.github.com/jhsbeat/11342294](https://gist.github.com/jhsbeat/11342294)

In GistTest.java, after I exectued "testPutMappingTemplate()" method, I can get the mapping below.

{"my\_type":{"properties":{"dataId":{"type":"long"},"myFieldList":{"properties":{"myFieldExact":{"type":"string","index":"not\_analyzed","omit\_norms":true,"index\_options":"docs"}}}}}}

However, after I ran "testIndexNewObject()" method, I got the mapping below.

{"my\_type":{"properties":{"dataId":{"type":"long"},"myFieldList":{"properties":{"myFieldExact":{"type":"string"}}}}}}

Do I have to remove my whole index and recreate it?

On Sunday, April 27, 2014 6:51:00 PM UTC+9, David Pilato wrote:  
I think you are pasting here your actual data.

So it's hard to tell where you are doing something wrong.

May be you could GIST a full curl/SENSE recreation?

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 27 avr. 2014 à 11:36, Ho-sang Jeon [jhs...@gmail.com](mailto:jhs...@gmail.com) a écrit :

Thanks David Pilato.

However, as I mentioned, I could see the correct mappings for the correct index and type like below.

curl -XGET http://{my\_ip\_address}:9200/my\_index/my\_type/\_mapping/

{"my\_type":{"properties":{........ "myFieldExact":{"type":"string","index":"not\_analyzed","omit\_norms":true,"index\_options":"docs"},...... }}}

After I index a new document into the index I got the changed mapping result for the exactly same GET url.

curl -XGET http://{my\_ip\_address}:9200/my\_index/my\_type/\_mapping/

{"my\_type":{"properties":{........ "myFieldExact":{"type":"string"},...... }}}

Here are some more detailed information.  
I'm using Elasticsearch version 0.90.0.  
The field "myFieldExact" is actually in an array. The real documents seem like below.

myFieldList: [  
{  
myFieldExact: "ABCD-1"  
},  
{  
myFieldExact: "ABCD-2"  
},  
{  
myFieldExact: "ABCD-2"  
}  
]

On Sunday, April 27, 2014 5:52:03 PM UTC+9, David Pilato wrote:  
Probably your first mapping is incorrect or applied to another type or index.

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 27 avr. 2014 à 09:45, Ho-sang Jeon [jhs...@gmail.com](mailto:jhs...@gmail.com) a écrit :

I'm in trouble with the overwriting action of prepareIndex method in Elasticsearch Java API.

The problem is that my mapping definition has changed after new document has indexed.

First of all, I defined an mapping to set "not\_analyzed" index for a particular field.

String json = myMethodToGetMapping();  
PutMappingResponse pmrs = client.admin().indices().preparePutMapping("my\_index").setType("my\_type").setSource(json).setIgnoreConflicts(true).execute().actionGet();

if (pmrs == null || !pmrs.isAcknowledged()) {  
System.out.println("Put Mapping Failure.");  
} else {  
System.out.println("Put Mapping Success.");  
}

In my mapping string(json), there is a field has settings like below.

"myFieldExact":{  
"type":"string",  
"index": "not\_analyzed",  
"dynamic": false  
}

After the code has executed, I could see the proper mapping which I want to get.

curl -XGET http://{my\_ip\_address}:9200/my\_index/my\_type/\_mapping/

{"my\_type":{"properties":{........ "myFieldExact":{"type":"string","index":"not\_analyzed","omit\_norms":true,"index\_options":"docs"},...... }}}

HOWEVER, this mapping has been changed after I put some data using Java API prepareIndex.

MyObject myObject = new MyObject();  
myObject.setMyFieldExact("some-value");  
String json = new org.codehaus.jackson.map.ObjectMapper().writeValueAsString(myObject);  
client.prepareIndex("my\_index", "my\_type", "my\_id")  
.setSource(json).execute().actionGet();

The document successfully indexed into "my\_index/my\_type/my\_id".

Here is the problem I have.

After the new record has been indexed, the original mapping definition has changed like below.

curl -XGET http://{my\_ip\_address}:9200/my\_index/my\_type/\_mapping/

{"my\_type":{"properties":{........ "myFieldExact":{"type":"string"},...... }}}

In short, the "index":"not\_analyzed" property has been gone after the new document has indexed.

Is there anyone can help me?

## Thank you very much in advance.

## You received this message because you are subscribed to the Google Groups "elasticsearch" group. To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com). To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5ee40a83-272b-4843-ba6f-f79b78737942%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5ee40a83-272b-4843-ba6f-f79b78737942%40googlegroups.com). For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

## You received this message because you are subscribed to the Google Groups "elasticsearch" group. To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com). To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/fb95c354-b1ad-4920-940d-e678d430e9fc%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fb95c354-b1ad-4920-940d-e678d430e9fc%40googlegroups.com). For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/e9099a04-6b73-4eb0-b43a-dbc836067005%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e9099a04-6b73-4eb0-b43a-dbc836067005%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/etPan.535ec3a2.2d1d5ae9.16bd1%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.535ec3a2.2d1d5ae9.16bd1%40MacBook-Air-de-David.local).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:32am UTC](https://discuss.elastic.co/t/elasticsearch-java-api-prepareindex-overwrites-existing-mapping/17219/8 "2017-07-06T01:32:59Z")

</div>


