Update partial document by query



I would like to update a partial document by query using Elasticsearch 2.4.
I don't want to use the scripts tag because I don't want to enumerate all the fields, I would like to use a doc property like the simple update method. However it's not possible to write this part of the following code:

So the following code doesn't work:
index: MY_INDEX,
type: MY_TYPE,
body: {
query: {

Is there a solution? I have a workaround at the moment but I would like to update my document by query using only one request. Thanks.

(Alexander Reelsen) #2


I am not sure what you mean by scripts tag here? Can you elaborate?

you can use the reindex API with scripting which might cover your use-case?




Thank you for replying.
Indeed, it's not the "script tag" but the "script property" of the updateByQuery API. For example:

"script": {
  "inline": "ctx._source.likes++",
  "lang": "painless"

Instead of this script property I'd like to use a doc property, like the one for the update API because I want to update most of the properties of a document. But this property doesn't exist for the updateByQuery API.

I'm happy to use any other API. However, for the reindex API, the Elasticsearch documentation says "Just like _update_by_query, _reindex gets a snapshot of the source index but its target must be a different index so version conflicts are unlikely". So I don't think this API is suitable for my needs since I don't want to change the index. I would like to update the document as a partial one.


(Alexander Reelsen) #4


ah I see. I think then it makes most sense to use a scroll search and create bulk requests that use the update API.



Thanks again for replying.

It's what I would have liked to avoid. Because I want to update only one document each time. For now I'm doing that, but I would have prefered to process only one update instead of a get and then an update. Even if I know an update is not only an update under the hood.

I'd like to use Elasticsearch as a datastore and not only as a search engine. I understand this kind of feature is not really necessary for a search engine. I don't have to do many updates, so getting the data before updating them is acceptable.

Thanks anyway for your help.

(system) #6

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