# Elasticsearch removing field inside field

**URL:** https://discuss.elastic.co/t/elasticsearch-removing-field-inside-field/171729
**Category:** Elasticsearch
**Created:** [March 11, 2019, 10:48am UTC](https://discuss.elastic.co/t/elasticsearch-removing-field-inside-field/171729 "2019-03-11T10:48:08Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![prasad.ram1431](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@prasad.ram1431](https://discuss.elastic.co/u/prasad.ram1431)
#### Post date: [March 11, 2019, 10:48am UTC](https://discuss.elastic.co/t/elasticsearch-removing-field-inside-field/171729/1 "2019-03-11T10:48:09Z")

</div>

Hi,

I would like to remove fields from my ES, which are below format,

```
{
	"parent": {
		"address": {
			"city": "abc",
			"state": "def"
		}
	}
}

```

By using "script": "ctx.\_source.remove("parent.address")", it's not removing address field.  
But when I try like, "script": "ctx.\_source.remove("parent")", complete parent is getting removed.

Could someone please help on removing field inside a field.

Thanks,  
Ram Prasad G

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [March 11, 2019, 11:12am UTC](https://discuss.elastic.co/t/elasticsearch-removing-field-inside-field/171729/2 "2019-03-11T11:12:32Z")

</div>

`ctx._source.parent.remove("address")` may be?

I guess it depends of the context of the script though. So a a complete example would help.

---

<div class="post-metadata">

### Author: ![prasad.ram1431](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@prasad.ram1431](https://discuss.elastic.co/u/prasad.ram1431)
#### Post date: [March 12, 2019, 12:59pm UTC](https://discuss.elastic.co/t/elasticsearch-removing-field-inside-field/171729/3 "2019-03-12T12:59:39Z")

</div>

Hi David,

ctx.\_source.parent.remove("address"), this is throwing below error.

{  
"error": {  
"root\_cause": [  
{  
"type": "remote\_transport\_exception",  
"reason": "[wRQCJZ1][x.x.x.x:9300][indices:data/write/update[s]]"  
}  
],  
"type": "illegal\_argument\_exception",  
"reason": "failed to execute script",  
"caused\_by": {  
"type": "script\_exception",  
"reason": "runtime error",  
"script\_stack": [  
"ctx.\_source.parent.remove("parent.address")",  
" ^---- HERE"  
],  
"script": "ctx.\_source.parent.remove("parent.address")",  
"lang": "painless",  
"caused\_by": {  
"type": "null\_pointer\_exception",  
"reason": null  
}  
}  
},  
"status": 400  
}

Meanwhile I left it, as we are not using this.

Thanks,  
Ram Prasad G

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [March 12, 2019, 1:23pm UTC](https://discuss.elastic.co/t/elasticsearch-removing-field-inside-field/171729/4 "2019-03-12T13:23:07Z")

</div>

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<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: [April 9, 2019, 1:23pm UTC](https://discuss.elastic.co/t/elasticsearch-removing-field-inside-field/171729/5 "2019-04-09T13:23:10Z")

</div>

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