# Document in ES having multiple source objects with same name

**URL:** <https://discuss.elastic.co/t/document-in-es-having-multiple-source-objects-with-same-name/7170>\
**Category:** Elasticsearch\
**Created:** [March 28, 2012, 10:50pm UTC](https://discuss.elastic.co/t/document-in-es-having-multiple-source-objects-with-same-name/7170 "2012-03-28T22:50:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![T\_Vinod\_Gupta](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@T\_Vinod\_Gupta](https://discuss.elastic.co/u/T_Vinod_Gupta)\
**Post date:** [March 28, 2012, 10:50pm UTC](https://discuss.elastic.co/t/document-in-es-having-multiple-source-objects-with-same-name/7170/1 "2012-03-28T22:50:36Z")

</div>

hi,  
im wondering how this is possible, seems counter intuitive. lets say, there  
is a document in ES with id "1" and it has a field called "num\_actions" and  
the value is 1. in order to increment just the value of "num\_actions", i  
create another document, copy the original fields into new content builder  
and then make the "num\_actions" = 2. after i store the document in the  
index, it shows that it has 2 fields, both with the name "num\_actions" with  
values 1 and 2.

this is what i do -

```
    GetRequestBuilder grb = client.prepareGet(indexName, type, id);
    GetResponse response = grb.execute().actionGet();
    IndexRequestBuilder irb = client.prepareIndex(indexName, type, id);
    Map<String,Object> messageFieldMap = response.getSource();
    XContentBuilder xcb = jsonBuilder().startObject();

    xcb = populateXContentFromMessageFieldMap(messageFieldMap, xcb); //

```

helper method to copy everything from messageFieldMap to xcb  
xcb = xcb.field("num\_actions", 2);  
xcb = xcb.endObject();  
IndexResponse indexResponse =  
irb.setSource(xcb).execute().actionGet();

one option to avoid this issue is to be intelligent  
inside populateXContentFromMessageFieldMap by having an exclude list. are  
there any other ways?

thanks

---

<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:** [March 29, 2012, 2:14pm UTC](https://discuss.elastic.co/t/document-in-es-having-multiple-source-objects-with-same-name/7170/2 "2012-03-29T14:14:26Z")

</div>

What you end up doing there is generate a document with two fields with teh  
same name. You can always update the field on the Map you get back from the  
get response, and then pass that Map to the index request (it accepts a map  
as well as the source).

On Thu, Mar 29, 2012 at 12:50 AM, T Vinod Gupta [tvinod@readypulse.com](mailto:tvinod@readypulse.com)wrote:

> hi,  
> im wondering how this is possible, seems counter intuitive. lets say,  
> there is a document in ES with id "1" and it has a field called  
> "num\_actions" and the value is 1. in order to increment just the value of  
> "num\_actions", i create another document, copy the original fields into new  
> content builder and then make the "num\_actions" = 2. after i store the  
> document in the index, it shows that it has 2 fields, both with the name  
> "num\_actions" with values 1 and 2.
> 
> this is what i do -
> 
> ```
> GetRequestBuilder grb = client.prepareGet(indexName, type, id);
> GetResponse response = grb.execute().actionGet();
> IndexRequestBuilder irb = client.prepareIndex(indexName, type, id);
> Map<String,Object> messageFieldMap = response.getSource();
> XContentBuilder xcb = jsonBuilder().startObject();
> 
> xcb = populateXContentFromMessageFieldMap(messageFieldMap, xcb);
> 
> ```
> 
> // helper method to copy everything from messageFieldMap to xcb  
> xcb = xcb.field("num\_actions", 2);  
> xcb = xcb.endObject();  
> IndexResponse indexResponse =  
> irb.setSource(xcb).execute().actionGet();
> 
> one option to avoid this issue is to be intelligent  
> inside populateXContentFromMessageFieldMap by having an exclude list. are  
> there any other ways?
> 
> thanks

---

<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:34am UTC](https://discuss.elastic.co/t/document-in-es-having-multiple-source-objects-with-same-name/7170/3 "2017-07-06T03:34:14Z")

</div>

Closed on July 6, 2017, 3:34am UTC


