# Logstash: ruby filter: how to create empty event?

**URL:** <https://discuss.elastic.co/t/logstash-ruby-filter-how-to-create-empty-event/123271>\
**Category:** Logstash\
**Created:** [March 9, 2018, 1:40pm UTC](https://discuss.elastic.co/t/logstash-ruby-filter-how-to-create-empty-event/123271 "2018-03-09T13:40:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![asp](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@asp](https://discuss.elastic.co/u/asp)\
**Post date:** [March 9, 2018, 1:40pm UTC](https://discuss.elastic.co/t/logstash-ruby-filter-how-to-create-empty-event/123271/1 "2018-03-09T13:40:53Z")

</div>

Hi,

Is it possible to create additional empty events in ruby filter plugin?

Only option I found in documentation [https://www.elastic.co/guide/en/logstash/current/plugins-filters-ruby.html](https://www.elastic.co/guide/en/logstash/current/plugins-filters-ruby.html) is to clone the current event.

```
filter {
  ruby {
    code => "new_event_block.call(event.clone)"
  }
}

```

I would like create new events on some conditionals. Because the new events should only take a few fields, it would be easier to build up from scratch and add fileds like @timestamp and my fields I would like to store than deleting all not needed fields afterwards.

Then I would like to add the array of events to the return array of filter(event) function.

---

<div class="post-metadata">

**Author:** ![talevy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/talevy/32/44896_2.png) [@talevy](https://discuss.elastic.co/u/talevy)\
**Post date:** [March 16, 2018, 5:04pm UTC](https://discuss.elastic.co/t/logstash-ruby-filter-how-to-create-empty-event/123271/2 "2018-03-16T17:04:27Z")

</div>

Hi @asp!

It is probably best to re-ask this under the Logstash category here: [https://discuss.elastic.co/c/logstash](https://discuss.elastic.co/c/logstash)

I believe you should be able to call `Event.new`?

---

<div class="post-metadata">

**Author:** ![asp](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@asp](https://discuss.elastic.co/u/asp)\
**Post date:** [March 21, 2018, 8:06am UTC](https://discuss.elastic.co/t/logstash-ruby-filter-how-to-create-empty-event/123271/3 "2018-03-21T08:06:05Z")

</div>

moved to correct sub forum

---

<div class="post-metadata">

**Author:** ![Jon\_D](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jon_d/32/25657_2.png) [@Jon\_D](https://discuss.elastic.co/u/Jon_D)\
**Post date:** [March 23, 2018, 1:53pm UTC](https://discuss.elastic.co/t/logstash-ruby-filter-how-to-create-empty-event/123271/4 "2018-03-23T13:53:15Z")

</div>

Hi,

I have the same requirement and I was able to find something that seems to work. The following filter example generates 2 new events (beside the original one):

```
filter {
    ruby {
            code => "
                    require 'pry'
                    generated = LogStash::Event.new
                    generated.set('somefield', 'somevalue')
                    new_event_block.call(generated)

                    anotherone = LogStash::Event.new({'message' => 'withsomedata'})
                    anotherone.set('other', 'need to set more data')
                    new_event_block.call(anotherone)
                    "
    }
}

```

Ruby's pretty new to me though, so if there's any good reason not to do it like this, some feedback would be much appreciated.

regards,  
Jonas

---

<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:** [April 20, 2018, 1:53pm UTC](https://discuss.elastic.co/t/logstash-ruby-filter-how-to-create-empty-event/123271/5 "2018-04-20T13:53:30Z")

</div>

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