# \_rubyexception when accessing 'event' array in ruby code

**URL:** <https://discuss.elastic.co/t/-rubyexception-when-accessing-event-array-in-ruby-code/57071>\
**Category:** Logstash\
**Created:** [August 3, 2016, 5:35am UTC](https://discuss.elastic.co/t/-rubyexception-when-accessing-event-array-in-ruby-code/57071 "2016-08-03T05:35:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![YuWatanabe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yuwatanabe/32/13259_2.png) [@YuWatanabe](https://discuss.elastic.co/u/YuWatanabe)\
**Post date:** [August 3, 2016, 5:35am UTC](https://discuss.elastic.co/t/-rubyexception-when-accessing-event-array-in-ruby-code/57071/1 "2016-08-03T05:35:34Z")

</div>

Hi!

I would like to get help with the code in ruby filter.

logstash version is 5.0.0 alpha4.

I am testing the code in ruby filter as below but I am getting \_rubyexception.

```
  ruby {
    code => "
      event['newfield'] = 'test'
    "
  }

```

The logstash.log shows as below,

`:timestamp=>"2016-08-03T15:26:47.291000+0900", :message=>"Ruby exception occurred: undefined method`[]=' for 2016-08-03T06:26:46.829Z test %{message}:LogStash::Event", :level=\>:error}`

I cant find the reason why ruby filter is unable to use event array.  
Could someone help me out?

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [August 8, 2016, 3:30pm UTC](https://discuss.elastic.co/t/-rubyexception-when-accessing-event-array-in-ruby-code/57071/2 "2016-08-08T15:30:47Z")

</div>

Logstash 5.0 uses the new event API. Try this:

```
event.set('newfield', 'test')

```

Additional reading: [https://github.com/elastic/logstash/issues/5141](https://github.com/elastic/logstash/issues/5141)

---

<div class="post-metadata">

**Author:** ![YuWatanabe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yuwatanabe/32/13259_2.png) [@YuWatanabe](https://discuss.elastic.co/u/YuWatanabe)\
**Post date:** [August 9, 2016, 1:02am UTC](https://discuss.elastic.co/t/-rubyexception-when-accessing-event-array-in-ruby-code/57071/3 "2016-08-09T01:02:50Z")

</div>

@magnusbaeck

Thank 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:** [July 6, 2017, 4:44am UTC](https://discuss.elastic.co/t/-rubyexception-when-accessing-event-array-in-ruby-code/57071/4 "2017-07-06T04:44:17Z")

</div>


