# Able o add new nested array data, Could not not delete update

**URL:** https://discuss.elastic.co/t/able-o-add-new-nested-array-data-could-not-not-delete-update/97518
**Category:** Elasticsearch
**Created:** [August 18, 2017, 6:41am UTC](https://discuss.elastic.co/t/able-o-add-new-nested-array-data-could-not-not-delete-update/97518 "2017-08-18T06:41:37Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![harpreet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/harpreet/32/3413_2.png) [@harpreet](https://discuss.elastic.co/u/harpreet)
#### Post date: [August 18, 2017, 6:41am UTC](https://discuss.elastic.co/t/able-o-add-new-nested-array-data-could-not-not-delete-update/97518/1 "2017-08-18T06:41:37Z")

</div>

I am using ES 5.5.  
Here is what I am stuck at.  
I am able to add new nested array element.  
But I also need to update any existing ones.  
my mapping

```
{
	"email_misc": {
		"mappings": {
			"emails": {
				"properties": {
					"email": {
						"type": "text"
					},
					"email_data": {
						"type": "nested",
						"properties": {
							"created_time": {
								"type": "long"
							},
							"direct_email": {
								"type": "integer"
							},
							"email_id": {
								"type": "long"
							},
							"email_identifier": {
								"type": "text"
							},
							"email_priority": {
								"type": "integer"
							},
							"email_sent": {
								"type": "integer"
							},
							"email_subject": {
								"type": "text"
							},
							"mg_key": {
								"type": "text"
							},
							"recipient_email": {
								"type": "keyword"
							},
							"recipient_name": {
								"type": "text"
							},
							"status_bounced": {
								"type": "integer"
							},
							"status_clicked": {
								"type": "integer"
							},
							"status_complained": {
								"type": "integer"
							},
							"status_delivered": {
								"type": "integer"
							},
							"status_dropped": {
								"type": "integer"
							},
							"status_opened": {
								"type": "integer"
							},
							"status_unsubscribed": {
								"type": "integer"
							}
						}
					},
					"email_key": {
						"type": "keyword"
					},
					"recipient_name": {
						"type": "text",
						"fields": {
							"keyword": {
								"type": "keyword",
								"ignore_above": 256
							}
						}
					}
				}
			}
		}
	}
}

```

I have a record like  
 ![Selection_006](https://us1.discourse-cdn.com/elastic/original/3X/b/8/b8d8cda71c7c0beef72969e50b10d6fb77de086b.jpg)

i want to update the status a nested record  
 ![Selection_007](https://us1.discourse-cdn.com/elastic/original/3X/5/8/58415419ef0ac0a5805f3e9925f90b52e0f02ba3.jpg)  
I tried

```
{
  "script": "for (int i = 0; i < ctx._source.email_data.size();i++){if(ctx._source.email_data[i].email_id == params.id){ctx._source.email_data.remove(i);i--;}}",
  "params": {
    "id": 165
  }
}

```

gave me  
 ![Selection_008](https://us1.discourse-cdn.com/elastic/original/3X/9/c/9ccee0c03d9a62297d07e3cb2755ff446893e6a2.jpg)

but not data is removed.  
I also tried

```
{
  "script": "for (int i = 0; i < ctx._source.email_data.size(); i++){if(ctx._source.email_data[i].email_id == params.remove_id){ctx._source.email_data[i].email_subject = 'Updated John';}}",
  "params": {
    "id": 165
  }
}

```

ALSO gave me success but nothing was updated.

what is the correct way to do it.

thank you

---

<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 15, 2017, 6:41am UTC](https://discuss.elastic.co/t/able-o-add-new-nested-array-data-could-not-not-delete-update/97518/2 "2017-09-15T06:41:51Z")

</div>

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