# Ruby filter - How to add fields?

**URL:** <https://discuss.elastic.co/t/ruby-filter-how-to-add-fields/43272>\
**Category:** Logstash\
**Created:** [March 2, 2016, 4:34pm UTC](https://discuss.elastic.co/t/ruby-filter-how-to-add-fields/43272 "2016-03-02T16:34:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kryten](https://avatars.discourse-cdn.com/v4/letter/k/58956e/32.png) [@Kryten](https://discuss.elastic.co/u/Kryten)\
**Post date:** [March 2, 2016, 4:34pm UTC](https://discuss.elastic.co/t/ruby-filter-how-to-add-fields/43272/1 "2016-03-02T16:34:18Z")

</div>

Hi

I'm trying to do this:

```
if [directive] {
	
		ruby {
	
			code => 
				"if event['directive'] <=30
					event[scenario] = 'scenario_one'
				 end
				 "
			
		}
	}

```

Basically if the directive field exists (which I have already converted to an integer) then I want to test its value against several conditionals then depending on where the value falls I need to **add a new field**"scenario" with the scenario name Eg "scenario\_one".

Can't seem to get Logstash to co-operate as it is complaining about undefined field "scenario".

I would appreciate any advice. Thanks.

**SOLVED**

I forgot to wrap the new field name in single quotes!!

This worked:

`event['scenario'] = 'scenario_one'`

Awesome... the ruby filter is so powerful!

---

<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:08am UTC](https://discuss.elastic.co/t/ruby-filter-how-to-add-fields/43272/2 "2017-07-06T05:08:45Z")

</div>


