# How to nest all fields in an event under a new field in logstash?

**URL:** <https://discuss.elastic.co/t/how-to-nest-all-fields-in-an-event-under-a-new-field-in-logstash/205688>\
**Category:** Logstash\
**Created:** [October 29, 2019, 2:17pm UTC](https://discuss.elastic.co/t/how-to-nest-all-fields-in-an-event-under-a-new-field-in-logstash/205688 "2019-10-29T14:17:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yuval\_Khalifa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yuval_khalifa/32/9604_2.png) [@Yuval\_Khalifa](https://discuss.elastic.co/u/Yuval_Khalifa)\
**Post date:** [October 29, 2019, 2:17pm UTC](https://discuss.elastic.co/t/how-to-nest-all-fields-in-an-event-under-a-new-field-in-logstash/205688/1 "2019-10-29T14:17:05Z")

</div>

Hi all,

How can use logstash to convert an event like this:  
{  
"@timestamp": "2019-10-29T13:33:46.378Z",  
"message": "p\_name=yuval;p\_surname=khalifa;p\_age=41",  
"host": "yuvalk",  
"p\_age": "41",  
"@version": "1",  
"p\_surname": "khalifa",  
"p\_name": "yuval"  
}

to this:  
{  
"security": {  
"@timestamp": "2019-10-29T13:33:46.378Z",  
"message": "p\_name=yuval;p\_surname=khalifa;p\_age=41",  
"host": "yuvalk",  
"p\_age": "41",  
"@version": "1",  
"p\_surname": "khalifa",  
"p\_name": "yuval"  
}  
}

without handling each field individually by its name.  
Is there a way to do that?

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [October 29, 2019, 2:21pm UTC](https://discuss.elastic.co/t/how-to-nest-all-fields-in-an-event-under-a-new-field-in-logstash/205688/2 "2019-10-29T14:21:34Z")

</div>

You could do it using ruby

```
    ruby {
        code => '
            event.to_hash.each { |k, v|
                event.set("[security][#{k}]", v)
                event.remove(k)
            }
        '
    }

```

But note that not having a @timestamp field may not work out well for 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:** [November 26, 2019, 2:21pm UTC](https://discuss.elastic.co/t/how-to-nest-all-fields-in-an-event-under-a-new-field-in-logstash/205688/3 "2019-11-26T14:21:39Z")

</div>

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