Elastic Search Remove Elements From Nested Object

I have created an index in elastic search with a nested type field. and added documents into the index. Now I want to remove some elements from nested objects who match the condition using UpdateByQuery. I have tried the following query to but getting Conflict error.

POST test/documents/_update_by_query
    "script": {
        "source": "for(int i= 0; i< ctx._source.address.size(); i++){if(ctx._source.address[i].city == params.city && ctx._source.address[i].state == params.state){ctx._source.address.remove(i)}}",
        "params": {
            "city": "Mumbai",
            "state": "Maharashtra"
    "query": {
        "bool": {
            "must": [{
                "term": {
                    "uid": "123"

We have multiple documents whose uid is "123" Is any other option to remove elements from a nested object without getting a Conflict error? How I can solve this kindly Help me here.

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