How to update multiple type in JAVA API?


(kikuchan) #1

Hello

I'd like to update multiple type in JAVA API.

I created the following method.


public void update(String index, String type, String, id, List< String> fieldList, List< String> valueList)
{
UpdateRequest updateRequest = new UpdateRequest(index, type, id)
for(int i = 0; i < fieldList.size(); ++i)
{
String field = fieldList.get(i);
String value = valueList.get(i);
updateRequest.doc(jsonBuilder().startObject()
.field(field, value).endObject());
}
client.update(updateRequest).get();
}

and I used this method like following code.


List< String> fieldList = new ArrayList< String>();
List< String> valueList = new valueList< String>();

fieldList.add("user");
valueList.add("John");
fieldList.add("Message");
valueList.add("updating");

classname.update("index","type","id",fieldList,valueList);


but, it only update "Message".

I'd like to update "user" and "Message";

How to update multiple type in JAVA API?


(David Pilato) #2

I would do something like:

XContentBuilder builder = jsonBuilder().startObject();

for(int i = 0; i < fieldList.size(); ++i) {
  builder.field(fieldList.get(i), valueList.get(i));
}

UpdateRequest updateRequest = new UpdateRequest(index, type, id).doc(builder.endObject());
client.update(updateRequest).get();

(kikuchan) #3

thanks for helping me.
I'm trying to do it!!


(system) #4