Find a string and replace with another in all the documents

Hi,

The problem I am trying to solve is to update a field with a string with another string in all the documents wherever you find it.

So lets consider this:

  1. I have 5 documents.
  2. Two of the documents have string "text" in field abc and three of the documents have same string "text" in field xyz.
  3. I want to update all the 5 documents replacing "text" with "text1".
  4. I tried below query and it does update all the documents but in addition to that it adds a new field xyz in the documents which had field abc with string "text" and adds the field abc to the documents which had field xyz.

Query:
POST log/_update_by_query?refresh=true
{
"script": {
"inline": "ctx._source.abc='text1';ctx._source.xyz='text1'"
},
"query": {
"multi_match" : {
"query": "text",
"fields": [ "abc", "xyz" ]
}
}
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.