# Restrictions on the Code block in Ruby filter

**URL:** <https://discuss.elastic.co/t/restrictions-on-the-code-block-in-ruby-filter/28366>\
**Category:** Logstash\
**Created:** [August 31, 2015, 5:30pm UTC](https://discuss.elastic.co/t/restrictions-on-the-code-block-in-ruby-filter/28366 "2015-08-31T17:30:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rishi](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@rishi](https://discuss.elastic.co/u/rishi)\
**Post date:** [August 31, 2015, 5:30pm UTC](https://discuss.elastic.co/t/restrictions-on-the-code-block-in-ruby-filter/28366/1 "2015-08-31T17:30:57Z")

</div>

The code that can be put into the ruby filter [1] - are there restrictions on it in any way, such as say it should be relatively simple/short? Can I put multi line ruby code in there? How do I `require` other gems in the code block?

[1]

```auto
filter {
  ruby {
    code => ...
  }
}

```

---

<div class="post-metadata">

**Author:** ![pierhugues](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pierhugues/32/48383_2.png) [@pierhugues](https://discuss.elastic.co/u/pierhugues)\
**Post date:** [September 2, 2015, 12:42pm UTC](https://discuss.elastic.co/t/restrictions-on-the-code-block-in-ruby-filter/28366/2 "2015-09-02T12:42:37Z")

</div>

Hello, currently there is no restrictions about the code or the size of the code.  
If your code require some gems that are not included with logstash it is much easier to write your own plugin than to use the ruby filter.

---

<div class="post-metadata">

**Author:** ![pierhugues](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pierhugues/32/48383_2.png) [@pierhugues](https://discuss.elastic.co/u/pierhugues)\
**Post date:** [September 2, 2015, 12:45pm UTC](https://discuss.elastic.co/t/restrictions-on-the-code-block-in-ruby-filter/28366/3 "2015-09-02T12:45:43Z")

</div>

if your code is multiples lines you can use `;` to separate the lines.

```auto
filter {
ruby { 
init => "@test = 0"
code = "event['counter'] = @test; @test +=1"
}

```

If you need specific gems use theses guides to write your plugins.  
[https://www.elastic.co/guide/en/logstash/current/contributing-to-logstash.html](https://www.elastic.co/guide/en/logstash/current/contributing-to-logstash.html)

If you are familiar with ruby, the plugins are simple gems.

---

<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, 5:30am UTC](https://discuss.elastic.co/t/restrictions-on-the-code-block-in-ruby-filter/28366/4 "2017-07-06T05:30:22Z")

</div>


