# Removing and renaming subsubfield with ruby code

**URL:** <https://discuss.elastic.co/t/removing-and-renaming-subsubfield-with-ruby-code/87695>\
**Category:** Logstash\
**Created:** [May 31, 2017, 8:31am UTC](https://discuss.elastic.co/t/removing-and-renaming-subsubfield-with-ruby-code/87695 "2017-05-31T08:31:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![toger](https://avatars.discourse-cdn.com/v4/letter/t/f14d63/32.png) [@toger](https://discuss.elastic.co/u/toger)\
**Post date:** [May 31, 2017, 8:31am UTC](https://discuss.elastic.co/t/removing-and-renaming-subsubfield-with-ruby-code/87695/1 "2017-05-31T08:31:01Z")

</div>

Hi,  
I am trying to remove all the data\_type subsubfield from an JSON array that looks like :  
"doc": {  
"subdoc1": {  
"content": "valuex"  
"data\_type": "valuey"  
},  
"subdoc2": {  
"content": "value2"  
"data\_type": "valuey"

i used the mutate filter to remove\_fields all that data\_type fields :  
remove\_field =\> "[doc][subdoc1][data\_type]"  
remove\_field =\> "[doc][subdoc2][data\_type]"  
...  
Problem is that doc document contains 100 subdoc value...

Is it possible to do it easier, like with a ruby code filter ?

Last thing, is that i would like to rename all the remaining fields doc.subdocX.content to the top level field subdocX, [doc][subdoc1][content] =\> [subdoc1]

I would like avoid the mutate rename that force me to write the 100 rules for each subdocX field, and replace it with a ruby code filter.  
I am using LS5.4 with the new Event API.

Thanks in advance.

---

<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:** [June 28, 2017, 8:31am UTC](https://discuss.elastic.co/t/removing-and-renaming-subsubfield-with-ruby-code/87695/2 "2017-06-28T08:31:50Z")

</div>

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