Update(upsert) with query support


(Hitesh Baldaniya) #1

Hi All,

Consider following situation.

PUT {{Index}}/{{Type}}/{{ID}}?query={"range": {"version": {"lt": 2}}} { "doc": { "title": "Test1" "version": 2 } }

I want to upsert document if it absent, otherwise update the document with query where if current document has version less than incoming version then only update.

This needs to be done in single call as architecture of writing document in ES is with large amount of concurrent requests. So if any request with lesser version comes later for document update we want to ignore those requests.

I am unable to find out such a call, So please can anyone help in it?


(Christian Dahlqvist) #2

Have a look at scripted updates.


(Hitesh Baldaniya) #3

Thanks Christina,

But complete update of document is not satisfied by scripted updates. Instead scripts any possibilities of adding "body" parameter where we can specify the document to be updated?


(Christian Dahlqvist) #4

Will the upsert option not work?


(Hitesh Baldaniya) #5

Hi Christina,

"Upsert" works currently because if there is no such "_id" then it creates automatically.

What I expect is "Update API Document" call with query and body to update document, not "Update By Query" as it doesn't satisfy requirement of adding body.

Thanks,


(Christian Dahlqvist) #6

As far as I know there is no API like that, but I think you should be able to pass your document as parameter (as well as in the upset field) and then perform the condition check and update through the script.


(system) #7

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.