# Update API - how to remove inner fields from objects via script?

**URL:** https://discuss.elastic.co/t/update-api-how-to-remove-inner-fields-from-objects-via-script/22296
**Category:** Elasticsearch
**Created:** [February 20, 2015, 3:54pm UTC](https://discuss.elastic.co/t/update-api-how-to-remove-inner-fields-from-objects-via-script/22296 "2015-02-20T15:54:30Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![daflookie](https://avatars.discourse-cdn.com/v4/letter/d/46a35a/32.png) [@daflookie](https://discuss.elastic.co/u/daflookie)
#### Post date: [February 20, 2015, 3:54pm UTC](https://discuss.elastic.co/t/update-api-how-to-remove-inner-fields-from-objects-via-script/22296/1 "2015-02-20T15:54:30Z")

</div>

I have an index that supports dynamic mappings under a field of type Object  
that we named custom. My doc also has other objects properties with inner  
props. I attached an abbreviated mapping - notice my object for "realm"  
and it's properties

Using the Update API I can remove a field per the docs  
[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-update.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-update.html)  
_if_ it's a top level field. For example this works great:

POST  
/test-timbr-2015.02.19/event/0f78c6b6-a30b-436e-bad7-4234654fc5bb/\_update  
{  
"script" : "ctx.\_source.remove("threadid")"  
}

However, when I run the script against a document that has a field nested  
in a specific object graph the specified field doesn't get deleted. I'm  
using dot notation as you can see, and when I run this ES comes back with a  
HTTP 200 and the \_version property gets incremented.

POST  
/test-timbr-2015.02.19/event/0f78c6b6-a30b-436e-bad7-4234654fc5bb/\_update  
{  
"script" : "ctx.\_source.remove("realm.name")"  
}

How can I get inner properties like this removed via the Update API.

Thanks for your help.  
Steve

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/9d4e960e-7a90-4a64-9f53-d7391b15b3a1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9d4e960e-7a90-4a64-9f53-d7391b15b3a1%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![daflookie](https://avatars.discourse-cdn.com/v4/letter/d/46a35a/32.png) [@daflookie](https://discuss.elastic.co/u/daflookie)
#### Post date: [February 22, 2015, 1:54pm UTC](https://discuss.elastic.co/t/update-api-how-to-remove-inner-fields-from-objects-via-script/22296/2 "2015-02-22T13:54:51Z")

</div>

Nevermind folks thanks anyway. I took a look at the ES source. Each  
object in the doc has it's own methods such as remove():

POST  
/test-timbr-2015.02.19/event/0f78c6b6-a30b-436e-bad7-4234654fc5bb/\_update  
{  
"script" : "ctx.\_source.realm.remove("name [http://realm.name/](http://realm.name/)")"  
}

On Friday, February 20, 2015 at 10:54:30 AM UTC-5, Steve Flook wrote:

> I have an index that supports dynamic mappings under a field of type  
> Object that we named custom. My doc also has other objects properties with  
> inner props. I attached an abbreviated mapping - notice my object for  
> "realm" and it's properties
> 
> Using the Update API I can remove a field per the docs  
> [http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-update.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-update.html)  
> _if_ it's a top level field. For example this works great:
> 
> POST  
> /test-timbr-2015.02.19/event/0f78c6b6-a30b-436e-bad7-4234654fc5bb/\_update  
> {  
> "script" : "ctx.\_source.remove("threadid")"  
> }
> 
> However, when I run the script against a document that has a field nested  
> in a specific object graph the specified field doesn't get deleted. I'm  
> using dot notation as you can see, and when I run this ES comes back with a  
> HTTP 200 and the \_version property gets incremented.
> 
> POST  
> /test-timbr-2015.02.19/event/0f78c6b6-a30b-436e-bad7-4234654fc5bb/\_update  
> {  
> "script" : "ctx.\_source.remove("realm.name")"  
> }
> 
> How can I get inner properties like this removed via the Update API.
> 
> Thanks for your help.  
> Steve

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/e608a60c-0741-4abb-a82d-0d2515c4359d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e608a60c-0741-4abb-a82d-0d2515c4359d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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: [July 6, 2017, 12:30am UTC](https://discuss.elastic.co/t/update-api-how-to-remove-inner-fields-from-objects-via-script/22296/3 "2017-07-06T00:30:57Z")

</div>


