1

Hi Below is my document

 "catid": [
           514500
          ],
 "studentid": 5282439,

In this catid field , I want to add new element 543 , where studentid = 5282439

I am trying the below query but it's giving me an exception

POST /parts/_update_by_query
{
  "query": {
     "match": {
        "studentid": 5282439
     }
  },
  "script" : "ctx._source.catid+= [543 ]"
}
 

I am getting the below exception:

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

2 Answers 2

5

--> If the above answer doesn't work try this one

POST /parts/_update_by_query
    {
      "query": {
        "match": {
          "studentid": 5282439
        }
      },
      "script" : {
          "lang":"painless",
         "inline": "ctx._source.catid.add(params.newsupp)",
         "params":{
             "newsupp":5302
      }
    }
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Please consider adding an explanation as to why this is the answer.
4

The script part is not correct, change it to this instead (i.e. move the script to the script.inline property):

POST /parts/_update_by_query
{
  "query": {
    "match": {
      "studentid": 5282439
    }
  },
  "script" : {
     "inline": "ctx._source.catid += [543 ]"
  }
}

4 Comments

Hi Val , Thanks , but when I ran the above query m getting the following exception
"type": "class_cast_exception", "reason": "Cannot apply [+] operation to types [java.util.ArrayList] and [java.util.ArrayList]."
I'm using ES 5.2.2 Version
Remove the square brackets

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.