2

I am trying to run update by query on my elasticsearch index using the method provided in this answer. This is the query that I've been trying to run:

curl -XPOST 'localhost:9200/my_index/_update_by_query' -d '
{
  "query":{
    "match":{
      "latest_uuid":"d56ffe2095f511e6bcdd0acbdf0298e3"
    }
  },
  "script" : "ctx._source.is_in_stock = \"false\";"
}'

But I keep getting the following error:

{
    "error": {
        "root_cause": [
            {
                "type": "class_cast_exception",
                "reason": "java.lang.String cannot be cast to java.util.Map"
            }
        ],
        "type": "class_cast_exception",
        "reason": "java.lang.String cannot be cast to java.util.Map"
    },
    "status": 500
}

What am I doing wrong here?

1
  • try "_update_by_query?is_in_stock=false" and delete script line to see if problem is script Commented Oct 26, 2016 at 10:56

2 Answers 2

1

Found the solution.

Turns out that I had to use the following as script:

"script":{"inline":"ctx._source.is_in_stock = false"}
Sign up to request clarification or add additional context in comments.

1 Comment

This is the answer. OMG, it's so weird that for single document _update, you can straight away pass a string script, but for _update_by_query you need to use the Map version
1

I think problem can be the \"false\" (String value) who no want to be cast.

curl -XPOST 'localhost:9200/my_index/_update_by_query' -d '
{
  "query":{
    "match":{
      "latest_uuid":"d56ffe2095f511e6bcdd0acbdf0298e3"
    }
  },
  "script" : "ctx._source.is_in_stock = false;"
}'

You can first try it. Waiting your feedback ! :)

2 Comments

Hi, I found the problem and have added an answer corresponding to that. Thanks for the help! :)
Yes I see, we post in the same time, GGWP !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.