# ELasticsearch 5.4 Remove nested field

**URL:** https://discuss.elastic.co/t/elasticsearch-5-4-remove-nested-field/92600
**Category:** Elasticsearch
**Created:** [July 11, 2017, 8:17am UTC](https://discuss.elastic.co/t/elasticsearch-5-4-remove-nested-field/92600 "2017-07-11T08:17:59Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Vikentyi](https://avatars.discourse-cdn.com/v4/letter/v/41988e/32.png) [@Vikentyi](https://discuss.elastic.co/u/Vikentyi)
#### Post date: [July 11, 2017, 8:17am UTC](https://discuss.elastic.co/t/elasticsearch-5-4-remove-nested-field/92600/1 "2017-07-11T08:17:59Z")

</div>

Hello. I have different types of fields in my index type:

{  
"test\_index": {  
"mappings": {  
"search\_type": {  
"properties": {  
"keywords": {  
"type": "keyword"  
},  
"person": {  
"properties": {  
"relation": {  
"properties": {  
"subject": {  
"type": "nested",  
"properties": {  
"first": {  
"type": "keyword"  
}  
},  
"last": {  
"type": "keyword"  
}  
}  
}  
}  
}  
}  
}  
},  
"relation": {  
"properties": {  
"first": {  
"type": "keyword"  
}  
},  
"last": {  
"type": "keyword"  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}

I want to remove fields and I am using reindex, it works fine with simple field like 'keywords':

ReindexAction.INSTANCE.newRequestBuilder( m\_transportClient )  
.source( "test\_index" )  
.destination( "test\_index\_new" )  
.script( new Script( "if (ctx.\_type=="search\_type") { ctx.\_source.remove("keywords") }" ) ).get();

But how should I build the script if I want to delete:

1. person.relation.subject.last (field from nested)
2. person.relation.subject (nested field)
3. relation.first (field from composite field)
4. relation (composite field with it's children)

---

<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: [August 8, 2017, 8:18am UTC](https://discuss.elastic.co/t/elasticsearch-5-4-remove-nested-field/92600/2 "2017-08-08T08:18:22Z")

</div>

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