ElasticSearch Illegal list shortcut value [id] "Update By Query"

2.1k views Asked by At

I get Illegal list shortcut value [id]. trying to update this document with this query. What Am I missing

events" : { "type" : "nested" }

location: {"type" : "nested"} nested type of objects

id: {"type" : "text"}

POST event_lists/_update_by_query?conflicts=proceed
{
  "script": {
     "lang": "painless",
      "source": """
        for (int i=0; i< ctx._source.events.length; i++){
          if(params.event_ids.contains(ctx._source.events[i].id)){
           ctx._source.events[i].location = params.location;
                 break;
                }
         }
         """,
         "params": {
                      "event_ids":  ["12345"],
                      "location": location_object
                    }
                    
  }
}

When trying to use Kibana to debug

Debug.explain(ctx._source.events[i].id); 

I get 
     "root_cause": [
      {
        "type": "script_exception",
        "reason": "runtime error",
        "painless_class": "java.lang.String",
        "to_string": "ETo3zoABiBlDN0geqAGN",
        "java_class": "java.lang.String",
        "script_stack": [
          "Debug.explain(ctx._source.events[i].id); \n          ",
          "                                   ^---- HERE"
        ]

1

There are 1 answers

0
Maged Makled On BEST ANSWER

I ended up doing a check if the object is a list vs. an object and it seems to be working.

for (event in ctx._source.events ){
  if(event instanceof List && event.size() > 0) {
    if(params.event_ids.contains(event[0].id)){
      event[0].location = params.location;
    break;
    }
    }else{
      if(params.event_ids.contains(event.id)){
        event.location = params.location;
      break;
      }
      }
      }