I am using this code in python for updating my docs in elasticsearch. It\'s working fine but it\'s difficult to use it for a millions docs because I have to initialise the
Using the update_by_query
(not the update
) and the script
, you should be able to update the documents that match your query.
q = {
"script": {
"inline": "ctx._source.Device='Test'",
"lang": "painless"
},
"query": {
"match": {
"Device": "Boiler"
}
}
}
es.update_by_query(body=q, doc_type='AAA', index='testindex')
The above worked for me. The q
finds the documents that match your query and the script updates the value using the _source
of each document.
I hope it works for you too, possibly with some adjustment on the query you want to use.