# How can I create new events in ruby filter?

**URL:** https://discuss.elastic.co/t/how-can-i-create-new-events-in-ruby-filter/63199
**Category:** Logstash
**Created:** [October 17, 2016, 3:38pm UTC](https://discuss.elastic.co/t/how-can-i-create-new-events-in-ruby-filter/63199 "2016-10-17T15:38:51Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![CraigFoote](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/craigfoote/32/4571_2.png) [@CraigFoote](https://discuss.elastic.co/u/CraigFoote)
#### Post date: [October 17, 2016, 3:38pm UTC](https://discuss.elastic.co/t/how-can-i-create-new-events-in-ruby-filter/63199/1 "2016-10-17T15:38:51Z")

</div>

I want to create new events from the existing one. I'd rather not create, compile and install a new filter if possible rather I'd like to use a ruby filter, e.g.

```
filter{
    ruby{
        code => '
            host_list = event["hostList"]
            # create new event for each host
            host_list.each do |host|
                new_event = event.clone
                # add/remove stuff from new_event
                yield new_event #FAILS! yield called out of block
            end
        '
    }
}

```

I understand why the yield fails but I don't know how to make the new event show up in rubydebug codec. Any help appreciated.

Craig

---

<div class="post-metadata">

### Author: ![CraigFoote](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/craigfoote/32/4571_2.png) [@CraigFoote](https://discuss.elastic.co/u/CraigFoote)
#### Post date: [October 17, 2016, 5:46pm UTC](https://discuss.elastic.co/t/how-can-i-create-new-events-in-ruby-filter/63199/2 "2016-10-17T17:46:02Z")

</div>

Just saw this: [configuration - Logstash dynamically split events - Stack Overflow](http://stackoverflow.com/questions/26074782/logstash-dynamically-split-events)

> You need to resort to a custom filter for this (you can't call yield from a ruby code filter which is what's needed to generate new events).

---

<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, 4:33am UTC](https://discuss.elastic.co/t/how-can-i-create-new-events-in-ruby-filter/63199/3 "2017-07-06T04:33:54Z")

</div>


