Q:

How I can update data using "update_by_query" in Elasticsearch 2.x? 

I need multi update documents in elastic by some query.  I found one solution.  Like this:
{
    "query": {
        "term": {
            "name": "some name"
        }
    },
    "script": {
        "inline": "ctx._source.some_field = \"value\""
    }
}

But it's not exactly what I need.  Because one request will update 10, or 20 fields, for example.  So it's uncomfortable to generate "script" string for many fields.  Ideally, I need something like this:
{
    "query": {
        "term": {
            "name": "some name"
        }
    },
    "doc": {
        "field1": "value1",
        "field2": "value2",
        "field3": "value3",
        "field4": "value4",
        "field5": "value5",
        ...
        "fieldN": "valueN",
    }
}

In order to implement something like the above, I would appreciate an alternative

A:

You can use a script like this one:
  "script": {
    "inline": "fieldsAndValues.each{ k, v -> ctx._source[k] = \"${v}\" }",
    "lang": "groovy",
    "params": {
      "fieldsAndValues": {
        "field1": "value1",
        "field2": "value2",
        "field3": "value3"
      }
    }
  }

