Solutions For Elastic Search document Update For Multiple fields using JAVA Api Code

房东的猫 提交于 2019-12-12 04:18:53

问题


An exampes that demonstrates how we update multiple fields on elastic search document

Map<String, Object> updateObject = new HashMap<String, Object>();
updateObject.put("field1", "updated value for fields1");
updateObject.put("field2", "updated value for fields2");
updateObject.put("field3", "updated value for fields3");            
Boolean meessage = client.prepareUpdate("indexName","indextype","documentId").setDoc(updateObject).setRefresh(true).execute().actionGet();

indexName will be your index name IndexType will be your index type documentId will be your documentId which is going to update client is your ElasticSeach client for JAVA API


回答1:


I think your question is how to update multiple fields using JAVA api.

For that use BulkRequestBuilder

BulkRequestBuilder bulkRequest = client.prepareBulk();

bulkRequest.add(client.prepareUpdate("indexName","indextype","documentId") 
                .setScript("ctx._source.field1=" + newValueField1));

bulkRequest.add(client.prepareUpdate("indexName","indextype","documentId") 
                .setScript("ctx._source.field2=" + newValueField2));

BulkResponse bulkResponse = bulkRequest.execute().actionGet();

By this you can update multiple values within document



来源:https://stackoverflow.com/questions/21405003/solutions-for-elastic-search-document-update-for-multiple-fields-using-java-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!