Update(upsert) with query support

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?

Have a look at scripted updates.

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?

Will the upsert option not work?

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,

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.

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