How can i update a doc with script in java api 1.7


(LDA) #1

my method like this:
ESUtil.getClient().prepareUpdate("ttl", "doc", "1")
.setScript(new Script("ctx._source.gender = "male"" , ScriptService.ScriptType.INLINE, null, null))
.get();
but the Script class is not in api 1.7 ,?
please help me how can i use script in 1.7? i want to update a doc like this:
"script" : "lookNum=lookNum+1" ,but for update in 1.7 , i must query the result first and then update use UpdateRequest like this:
lookNum=lookNum+1;
UpdateRequest update=new UpdateRequest();
update.index(index).type(type).id(code);
XContentBuilder xcon=null;
try {
xcon = XContentFactory.jsonBuilder()
.startObject()
.field(upField, lookNum)
.endObject();
} catch (IOException e) {
e.printStackTrace();
}


(David Pilato) #2

Have a look at https://www.elastic.co/guide/en/elasticsearch/client/java-api/1.7/java-update-api.html


(system) #3