How do I remove a nested object element?

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.

1 Like

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

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