Problem with _update_by_the_query elastic search

200 Views Asked by At

Elasticsearch version is about 7.x I want to update all documents in an index and I find in the documentation that I have to use "_update_to_the_query". This is the code:

curl -XPOST 127.0.0.1:9200/hamlet-raw/_update_by_the_query -d'
{
"query": {
"match_all": {}
},
"script" : {
"speaker": "Hamlet"
}
}'

and I get this error:

{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Invalid type: expecting [_doc] but got [_update_by_the_query]"}],"type":"illegal_argument_exception","reason":"Invalid type: expecting [_doc] but got [_update_by_the_query]"},"status":400}

why? Any advice on update all documents by adding a new field and value ? thank you.

1

There are 1 best solutions below

1
On

Look the example in doc update by query using scripts:

Add your script inside section source.

POST my-index-000001/_update_by_query
{
  "script": {
    "source": "ctx._source.speaker = 'hammelt'",
    "lang": "painless"
  },
  "query": {
    "match_all": {}
  }
}