Find and replace in elasticsearch all documents


(Madhu Akula) #1

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:


(David Pilato) #2

Reindex API with a script?


(Madhu Akula) #3

@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


(Ravi Shanker Reddy) #4

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.


(David Pilato) #5

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


(Madhu Akula) #6

@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.


(Madhu Akula) #7

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


(Madhu Akula) #8

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?


(David Pilato) #9

What "did not work"?

Sorry I can't help without a full example.

This article explains how to post a complete example.


(Madhu Akula) #10

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


(system) closed #11