I'm new here.
I have about 200 thousand documents in one index, all have same type. I want to add one more field "category" (which is a keyword string) to every single document.
Is there a convenient way to achieve this? I know normally one query only gets 10000 documents
Thank you very much
POST index_name/_update_by_query
{
"script": {
"inline": "ctx._source.field_name = \"value\"",
"lang": "painless"
}
}
Late but hope this can help you.
You can use _update_by_query API.
Be aware that you can define conditions for your update with the query part of the request. If you just need to update all the documents in your index, you can simply delete the query part.
POST my-index-000001/_update_by_query
{
"script": {
"source": "ctx._source.count++",
"lang": "painless"
},
"query": {
"term": {
"user.id": "kimchy"
}
}
}
Note: the inline
option inside _update_by_query
is depreciated since 6.x. You should use source
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With