问题
I wanted to replace the single username in all my elasticsearch index documents. Is there any API query ?
I tried searching multiple but couldn't find. Any one has idea?
My scenario:
curl -XPOST 'http://localhost:9200/test/movies/' -d '{"user":"mad", "role":"tester"}'
curl -XPOST 'http://localhost:9200/test/movies/' -d '{"user":"bob", "role":"engineer"}'
curl -XPOST 'http://localhost:9200/test/movies/' -d '{"user":"cat", "role":"engineer"}'
curl -XPOST 'http://localhost:9200/test/movies/' -d '{"user":"bob", "role":"doctor"}'
I have the above data in the index called "test" and type "movies". Here I wanted to replace all the "bob" name with "alice".
Thanks
回答1:
update-by-query is the way to go.
POST /test/movies/_update_by_query
{
"script": {
"inline": "ctx._source.user = 'alice'"
},
"query": {
"term": {
"user": "bob"
}
}
}
Note: make sure to enable dynamic scripting in order for this to work.
来源:https://stackoverflow.com/questions/38636348/find-and-replace-in-elasticsearch-all-documents