Document in ES having multiple source objects with same name

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

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.comwrote:

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