在elasticsearch中查找和替换所有文档 [英] Find and replace in elasticsearch all documents

查看:43
本文介绍了在elasticsearch中查找和替换所有文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想替换所有 elasticsearch 索引文档中的单个用户名.是否有任何 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"}'

我在名为test"的索引中有上述数据并输入movies".这里我想用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".

谢谢

推荐答案

按查询更新 是要走的路.

POST /test/movies/_update_by_query
{
  "script": {
    "source": "ctx._source.user = 'alice'"
  },
  "query": {
    "term": {
      "user": "bob"
    }
  }
}

注意:确保 启用动态脚本 以使其正常工作.

Note: make sure to enable dynamic scripting in order for this to work.

这篇关于在elasticsearch中查找和替换所有文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆