Painless - proper syntax to remove string from list


(Paisley Singh) #1

Why does this work?

ctx._source.locations.remove(ctx._source.locations.indexOf(params.delete_location));

and not this?

ctx._source.locations.remove(params.delete_location);

I get this error:

"caused_by": {
        "type": "class_cast_exception",
        "reason": "class_cast_exception: null"
      }

I am trying to update a field that is a list of strings using update_by_query. I validated with the Painless debug tool, Debug.explain that params.delete_location is a string and ctx._source.locations is an ArrayList.

Using Elasticsearch version 5.5.


(Ryan Ernst) #2

The List.remove method exposed in painless is the variant that takes an index. Painless cannot do overloaded methods differing only by type, so there is no variant exposed that takes the object to remove.


(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.