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 =
one option to avoid this issue is to be intelligent
inside populateXContentFromMessageFieldMap by having an exclude list. are
there any other ways?