1

I am trying to update multiple documents on elasticsearch that were created with a wrong (for us) country name.

I am trying to do so by using "update_by_query" plugin version 2.5.0 (that should work with ES 1.5.2). plugin page

This is what I've tried:

POST incidents/political/_update_by_query
{
  "query":{
    "filtered":{
      "filter":{
        "bool":{
          "must":{
            "term":{
              "CountryName": "Cote d'Ivoire"          
            }
          }
        }
      }
    }
  },
  "script":{
    "inline":"ctx._source.CountryName = newName",
    "params":{
      "newName":"Cote dIvoire"
    }
  }
}

and the result is:

{
   "ok": true,
   "took": 9,
   "total": 2,
   "updated": 0,
   "indices": [
      {
         "incidents": {}
      }
   ]
}

I can see that it is able to find those two records but can't update them for some reason.

I have enable the needed settings on config file:

script.inline: on 
script.indexed: on
script.disable_dynamic: false

I am not sure what can be missing or wrong.

Yatiac
  • 1,820
  • 3
  • 15
  • 25

1 Answers1

2

Try to write the script part of your query like this:

 "script" : "ctx._source.CountryName = 'Cote dIvoire'"

Let me know if it works.

A Coder Gamer
  • 840
  • 1
  • 10
  • 31
  • thanks man! that worked like a charm. Can you tell me why my way wasn't working ? – Yatiac May 05 '16 at 21:08
  • 1
    Glad I could help. I'm not quite sure. I ran into the same problem few days ago and this way solved my problem. :) – A Coder Gamer May 05 '16 at 21:17
  • I ran into another issue, I need to add the quote but the script doesn't seem to accept special character. I tried by escaping it (\') or usin the html code (') but they didn't work. Any idea how to include it? – Yatiac May 06 '16 at 21:52
  • Hi @Yatiac, I think you can use quotes by using this five-character sequence '"'"' check this link: http://stackoverflow.com/questions/1250079/how-to-escape-single-quotes-within-single-quoted-strings Let me know if it works. – A Coder Gamer May 06 '16 at 22:01
  • or Can you try to escape it with \u0027 . Check this link: https://www.elastic.co/guide/en/elasticsearch/guide/current/char-filters.html – A Coder Gamer May 06 '16 at 22:09