在弹性搜索中查找和替换所有文档 [英] Find and replace in elasticsearch all documents
本文介绍了在弹性搜索中查找和替换所有文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在所有的弹性搜索索引文档中替换单个用户名。有没有任何API查询?
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?
我的场景:
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"}'
索引上面的数据称为测试,并键入电影。在这里我想用alice替换所有的bob名字。
I have the above data in the index called "test" and type "movies". Here I wanted to replace all the "bob" name with "alice".
谢谢
推荐答案
update- by-query 是要走的路。
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.
这篇关于在弹性搜索中查找和替换所有文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文