# Elastic Search Remove Elements From Nested Object

**URL:** <https://discuss.elastic.co/t/elastic-search-remove-elements-from-nested-object/245587>\
**Category:** Elasticsearch\
**Created:** [August 19, 2020, 11:25am UTC](https://discuss.elastic.co/t/elastic-search-remove-elements-from-nested-object/245587 "2020-08-19T11:25:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![surajdalvi](https://avatars.discourse-cdn.com/v4/letter/s/85f322/32.png) [@surajdalvi](https://discuss.elastic.co/u/surajdalvi)\
**Post date:** [August 19, 2020, 11:25am UTC](https://discuss.elastic.co/t/elastic-search-remove-elements-from-nested-object/245587/1 "2020-08-19T11:25:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 16, 2020, 11:25am UTC](https://discuss.elastic.co/t/elastic-search-remove-elements-from-nested-object/245587/2 "2020-09-16T11:25:10Z")

</div>

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