1

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!

4
  • Are you sure that your document fdfsfsfs-058f-437d-bc52-473808ba61c2 has a field called addresses which is not null? Commented Aug 3, 2021 at 14:01
  • Hi @Val, yes, i am, I checked that. Commented Aug 3, 2021 at 14:08
  • 1
    How many documents match your query? I bet there are more than one because you're using match instead of term? Commented Aug 3, 2021 at 14:11
  • You are right @Val! Thank you very much! Switching to "term" solved my problem. Commented Aug 3, 2021 at 14:17

1 Answer 1

1

I think that the match query actually matches several documents and one of them doesn't have any field called addresses.

You probably need to change to a term query in order to do an exact match and only select the single document that you would like to update.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.