问题
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