Find and replace in elasticsearch all documents

扶醉桌前 提交于 2019-11-28 06:22:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!