# Elasticsearch 6 remove an element from nested array of objects

**URL:** https://discuss.elastic.co/t/elasticsearch-6-remove-an-element-from-nested-array-of-objects/143499
**Category:** Elasticsearch
**Created:** [August 8, 2018, 11:20am UTC](https://discuss.elastic.co/t/elasticsearch-6-remove-an-element-from-nested-array-of-objects/143499 "2018-08-08T11:20:27Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Mohammad\_Jilani](https://avatars.discourse-cdn.com/v4/letter/m/7cd45c/32.png) [@Mohammad\_Jilani](https://discuss.elastic.co/u/Mohammad_Jilani)
#### Post date: [August 8, 2018, 11:20am UTC](https://discuss.elastic.co/t/elasticsearch-6-remove-an-element-from-nested-array-of-objects/143499/1 "2018-08-08T11:20:28Z")

</div>

Here is the index structure.

{  
"\_index": "my\_index2",  
"\_type": "\_doc",  
"\_id": "5",  
"\_score": 1,  
"\_source": {  
"group": "fans",  
"user": [  
{  
"first": "rayachoty-loki-one",  
"last": "Smith"  
},  
{  
"first": "hyderabad-loki-two",  
"last": "White"  
}  
]  
}  
want to remove objects from user array with last name "White"

I tried with the following query but doesn't help me out.

POST /my\_index2/\_doc/5/\_update{  
"script": "Map item\_to\_remove ;for(item in ctx.\_source.user){if (item['last'] == params.tweet\_id) {item\_to\_remove=item;}} ctx.\_source.user.remove(item\_to\_remove);",  
"params": {"tweet\_id": "White"}  
}

---

<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 5, 2018, 11:20am UTC](https://discuss.elastic.co/t/elasticsearch-6-remove-an-element-from-nested-array-of-objects/143499/2 "2018-09-05T11:20:39Z")

</div>

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