Find and replace in elasticsearch all documents

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?

Thanks in advance :slight_smile:

Reindex API with a script?

@dadoonet thanks for the reply. I am new to the elasticsearch API, If you don't mind could you please give an example?

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

Please mention which OS you are using. Ex (Linux, Windows)

And also to which scripting language you are familiar with. Then we can help you.

Look here: https://www.elastic.co/guide/en/elasticsearch/reference/2.3/docs-reindex.html

@dadoonet Thanks for this reference. I saw this link already, But I couldn't see any documentation for find and replace. Looks like it mostly contains reindexing of already existing using sort (or) field name changes.

I am not a programmer. If you know the answer could you please provide the API call for the given scenario. I really appreciate your time.

Thanks

Hello @dadoonet,

I have tried the below code

POST /_reindex
{
  "source": {
    "index": "test",
    "type": "movies"
  },
  "dest": {
    "index": "new_test"
    "query": {
      "term": {
        "pattern": "bob"
        "replacement": "alice"
      }
    }
  }
}

It didn't work. Any suggestions?

What "did not work"?

Sorry I can't help without a full example.

This article explains how to post a complete example.

Thanks for the help. I got working using update query. Here is the best answer rather re indexing.