# How do I remove a nested object element?

**URL:** https://discuss.elastic.co/t/how-do-i-remove-a-nested-object-element/90429
**Category:** Elasticsearch
**Created:** [June 22, 2017, 10:27am UTC](https://discuss.elastic.co/t/how-do-i-remove-a-nested-object-element/90429 "2017-06-22T10:27:03Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![waynesmallman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/waynesmallman/32/18596_2.png) [@waynesmallman](https://discuss.elastic.co/u/waynesmallman)
#### Post date: [June 22, 2017, 10:27am UTC](https://discuss.elastic.co/t/how-do-i-remove-a-nested-object-element/90429/1 "2017-06-22T10:27:04Z")

</div>

I'm using Elasticsearch 5.4, and attempting to remove an element from a nested datatype.

I have the following mapping:

```
"links_to_asset": {
    "type": "nested",
    "properties": {
        "note_link_id": {
            "type": "long"
        },
        "user_id": {
            "type": "long"
        },
        "creation": {
            "type": "date",
            "format": "date_hour_minute_second"
        },
        "modification": {
            "type": "date",
            "format": "date_hour_minute_second"
        },
        "to_asset": {
            "type": "integer"
        },
        "from_asset": {
            "type": "integer"
        },
        "comment": {
            "type": "text",
            "fields": {
                "std": {
                    "type": "text",
                    "analyzer": "asset_en_analyzer",
                    "fields": {
                        "std": {
                            "type": "text",
                            "analyzer": "standard"
                        }
                    }
                }
            }
        }
    }
}

```

I've tried the following in Postman:

> localhost:9200/asset/bookmark/20976/\_update?pretty

```
{
    "script": "ctx._source.links_to_asset.removeAll{it['note_link_id'] == id}",
    "params": {
        "id": 7343
    }
}

```

But I get the following error:

```
{
    "error": {
        "root_cause": [
            {
                "type": "remote_transport_exception",
                "reason": "[NvXYDwh][127.0.0.1:9300][indices:data/write/update[s]]"
            }
        ],
        "type": "illegal_argument_exception",
        "reason": "failed to execute script",
        "caused_by": {
            "type": "script_exception",
            "reason": "compile error",
            "script_stack": [
                "... .links_to_asset.removeAll{it['links_to_asset.note_ ...",
                " ^---- HERE"
            ],
            "script": "ctx._source.links_to_asset.removeAll{it['links_to_asset.note_link_id'] == id}",
            "lang": "painless",
            "caused_by": {
                "type": "illegal_argument_exception",
                "reason": "unexpected token ['{'] was expecting one of [{<EOF>, ';'}]."
            }
        }
    },
    "status": 400
}

```

The nested object is valid, as I've populated it with data. Also, `id` value is valid, too.

---

<div class="post-metadata">

### Author: ![waynesmallman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/waynesmallman/32/18596_2.png) [@waynesmallman](https://discuss.elastic.co/u/waynesmallman)
#### Post date: [June 28, 2017, 7:02pm UTC](https://discuss.elastic.co/t/how-do-i-remove-a-nested-object-element/90429/2 "2017-06-28T19:02:04Z")

</div>

Hi, is there anyone able to offer some advice, or — at least — documentation for the `removeAll` function?

---

<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: [July 26, 2017, 7:02pm UTC](https://discuss.elastic.co/t/how-do-i-remove-a-nested-object-element/90429/3 "2017-07-26T19:02:14Z")

</div>

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