java - Return a specific field from elasticsearch index or update query -
here part of code index or update document. want specific field value 'documentid' in '_source'.here 'json' jsonobject of document model.
string jsonforupdate = json.tostring(); string uuid = uuid.randomuuid().tostring(); json.put("documentid", uuid); string jsonforindex = json.tostring(); indexrequest indexrequest = new indexrequest(indexname, typename, documentmodel.getid()); indexrequest.source(jsonforindex); updateresponse updateresponse = elasticsearchtemplate.getclient().prepareupdate(indexname, typename , documentmodel.getid()).setdoc(jsonforupdate).setupsert(indexrequest).setfields("documentid").get();
i tried code value document field.
updateresponse.getgetresult().getfields().get("documentid").getvalue().tostring();
but didnt work me during updating document.works fine during indexing document.
if at: https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html
you can see following parameter can passed on update:
_source allows control if , how updated source should returned in response. default updated source not returned. see source filtering details.
this mean in prepareupdate
can use setfetchsource(true)
method, although bring full document.
update: version 2.3.3 can still use:
/** * explicitly specify fields returned. default, nothing returned. */ public updaterequestbuilder setfields(string... fields) { request.fields(fields); return this; }
elasticsearch doc: https://www.elastic.co/guide/en/elasticsearch/reference/2.3/docs-update.html
the method available on updaterequestbuilder, class of object returned prepareupdate.
Comments
Post a Comment