ElasticSerach API - update by query script params null_pointer_exception

I am new to the ElasticSearch and am i trying to make use of the _update_by_query route. I am sending this body:

{
"query": {
    "match": {
        "id": "fdfsfsfs-058f-437d-bc52-473808ba61c2"
    }
},
"script": {
    "inline": "ctx._source.addresses.add(params.data)",
    "params": {
        "data": {
            "street": "Road",
            "number": 15,
            "county": "WWW"
        }
    }
}

but I get the following response:

{
"error": {
    "root_cause": [
        {
            "type": "script_exception",
            "reason": "runtime error",
            "script_stack": [
                "ctx._source.addresses.add(params.data)",
                "                                ^---- HERE"
            ],
            "script": "ctx._source.addresses.add(params.data)",
            "lang": "painless",
            "position": {
                "offset": 30,
                "start": 0,
                "end": 36
            }
        }
    ],
    "type": "script_exception",
    "reason": "runtime error",
    "script_stack": [
        "ctx._source.addresses.add(params.data)",
        "                              ^---- HERE"
    ],
    "script": "ctx._source.addresses.add(params.data)",
    "lang": "painless",
    "position": {
        "offset": 30,
        "start": 0,
        "end": 36
    },
    "caused_by": {
        "type": "null_pointer_exception",
        "reason": null
    }
},
"status": 400
}

I don't know what could be the error, since I do pass my params and they are inside the "script" object. Does anyone have an idea of what could be wrong?

Thank you very much in advance!

The problem was that I was using "match", instead of "term", so my query returned multiple results.

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