0

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
  • 2
    I don't understand. What is the question? Commented Jan 28, 2014 at 12:06

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Hardik.I just post the solutions for multiple field update for Elastic Search using JAVA API. As i dont see any option for topic there thats why i posted it in questions
Oh than you should specify on top that this is the solution of particular problem,and at the end this is the QA site..anyways..edit your question so that people avoids such mislead . If you mentioned so i would tried directly your posted solution ..!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.