# Painless - proper syntax to remove string from list

**URL:** https://discuss.elastic.co/t/painless-proper-syntax-to-remove-string-from-list/132230
**Category:** Elasticsearch
**Created:** [May 16, 2018, 11:41pm UTC](https://discuss.elastic.co/t/painless-proper-syntax-to-remove-string-from-list/132230 "2018-05-16T23:41:44Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Paisley\_Singh](https://avatars.discourse-cdn.com/v4/letter/p/958977/32.png) [@Paisley\_Singh](https://discuss.elastic.co/u/Paisley_Singh)
#### Post date: [May 16, 2018, 11:41pm UTC](https://discuss.elastic.co/t/painless-proper-syntax-to-remove-string-from-list/132230/1 "2018-05-16T23:41:44Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)
#### Post date: [May 17, 2018, 4:18pm UTC](https://discuss.elastic.co/t/painless-proper-syntax-to-remove-string-from-list/132230/2 "2018-05-17T16:18:22Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [June 14, 2018, 4:18pm UTC](https://discuss.elastic.co/t/painless-proper-syntax-to-remove-string-from-list/132230/3 "2018-06-14T16:18:24Z")

</div>

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