Elasticsearch update by query - update ONLY the last document

Hello community,

I am new to the elasticsearch and I am trying to get the last document from my index and update its list of object.

I tried several queries e.g:

POST localhost:9200/test-index/_update_by_query

{
 "size":1,
 "sort": [{"timestamp":"asc"}],
  "script": {
      "inline": "ctx._source.addresses.add(params.address)",
        "params" : {
           "address" :{
                  "street": "Yemen Road",
                  "number": 15,
                  "county": "Yemen"
              }
        }
    }
}

But this updates all my documents. I guess that the script is applied before the size. I am stuck at this point and I would really like to do this in one API call.
What is the fastest way to do this?

Thank you in advance!

Update by query does not support a size. You would need to run a query first using size and sorting, and then use the update API on that single document.

@spinscale thank you for the answer. I knew how to do this with two api calls, was wondering is it possible to do it only with one. Thanks for confirming I need to use 2 calls.