Update By Query API

In the docs for Update By Query I see that you can use a script to update all documents matching a query.

POST twitter/_update_by_query
  "script": {
    "source": "ctx._source.likes++",
    "lang": "painless"
  "query": {
    "term": {
      "user": "kimchy"

Is there a way similar to the Update API to pass a partial doc, and have that updated for all the documents?

POST test/_doc/1/_update
    "doc" : {
        "tags" : ["tag1", "tag2", "tag3"]


I certainly thought about adding such a thing when I built update_by_query but I never ended up doing it. Originally I didn't implement it because I was try to implement the smallest thing that worked. Now I don't think it is a good choice. The "merge a partial document" behavior of update is from a time long before Elasticsearch had a fast and safe scripting language. I suppose "fast" isn't all that important here because the performance of update-by-query is dominated by indexing the documents, but "safe" is crucial here. The idea of the "merge" behavior was so that you didn't have to send big documents over the wire to Elasticsearch and that is legit nice. A few years ago when it wasn't safe to enable inline scripting by default that was the only way to safely do that. But now that we have painless we can write a script to make the change explicit.

So I admit I'm biased:

  1. I've worked on painless and I'm proud of it.
  2. The specifics of the "merge a partial document" behavior always confused me. Objects are merged but lists are replaced, at least that is how I remember it. I prefer to be explicit for this.

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