Search code examples
pythonamazon-web-serviceselasticsearchupdating

Issue in updating elastic search field


This how my result source looks like.

{"_source": {"Name": "Where's My Crown Angry birds 3","movie_id":69}}

I need to update the Name field as "'Where's My Crown'". I used the following query:

{"script": {"inline": "ctx._source.Name='Where's My Crown'","lang": "painless"},"query": {"match": {"movie_id": 69}}}

But I got this error:

{'type': 'illegal_argument_exception', 'reason': "unexpected token ['s'] was expecting one of [{<EOF>, ';'}]."}**

Please help me to fix this.


Solution

  • This is because of the fact that there is a single quote in "Where's My Crown" and that interferes with the single quotes around the whole string.

    Consider doing it like this (using params) instead:

    {  
       "script": {
           "inline": "ctx._source.Name = params.newName",
           "params": {
             "newName": "Where's My Crown"
           },
           "lang": "painless"
       },
       "query": {"match": {"movie_id": 69}}
    }