1

How can I insert a data into a index in elasticsearch using java api in the most efficient way .First I need to check if the entry exists using a field lets say log_id ,if it exists that I will update that entry else i will insert a new entry into elasticsearch .Is there any method in elasticsearch which does both.

1 Answer 1

1

You can do it in BULK ( if you are doing insert and update in bulk) Following is a simple example :

check if the log_id exists already:

if existing create Update json string \n should be there,

{ "update" : {"_id" : "1", "_type" : "type1", "_index" : "index1"} }\n{ "doc" : {"field2" : "value2"} }

else create a Insert Json like below \n should be there,

{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }\n{ "field1" : "value1" }

Have them in list and do the BULK API.

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

Comments

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.