# \[ERROR\]\[logstash.filters.ruby \] Ruby exception occurred: undefined method \`\[\]' for #\<LogStash::Event:0x9a18b32\>

**URL:** <https://discuss.elastic.co/t/error-logstash-filters-ruby-ruby-exception-occurred-undefined-method-for-logstash-0x9a18b32/269301>\
**Category:** Logstash\
**Created:** [April 6, 2021, 8:38am UTC](https://discuss.elastic.co/t/error-logstash-filters-ruby-ruby-exception-occurred-undefined-method-for-logstash-0x9a18b32/269301 "2021-04-06T08:38:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rumala](https://avatars.discourse-cdn.com/v4/letter/r/e56c9b/32.png) [@rumala](https://discuss.elastic.co/u/rumala)\
**Post date:** [April 6, 2021, 8:38am UTC](https://discuss.elastic.co/t/error-logstash-filters-ruby-ruby-exception-occurred-undefined-method-for-logstash-0x9a18b32/269301/1 "2021-04-06T08:38:00Z")

</div>

Hello experts,

I'm still learning about ELK. last week i set up my ELK lab. And I got error in my Logstash. I'm using logstash 7.5.1. I would like to parse through all fields of my Logstash and convert field starting with the word "time" to float. This is my configuration

```auto
    filter {
    date {
      match => ["timestamp", "ISO8601"]
    }
    ruby {
      code => "if event['event_type'] == 'fileinfo'; event['fileinfo']['type']=event['fileinfo']['magic'].to_s.split(',')[0]; end;"
    }
  if [src_ip] {
    if ![geoip.ip] {
      if [src_ip] {
        geoip {
          source => "src_ip"
          target => "geoip"
          add_field => ["[geoip][coordinates]", "%{[geoip][longitude]}" ]
          add_field => ["[geoip][coordinates]", "%{[geoip][latitude]}" ]
        }
        mutate {
          convert => ["[geoip][coordinates]", "float" ]
        }
      }
    }
  }
}

```

Any help would be great, as I have been stuck with this for the entire week.  
Thanks

---

<div class="post-metadata">

**Author:** ![Cad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cad/32/86661_2.png) [@Cad](https://discuss.elastic.co/u/Cad)\
**Post date:** [April 6, 2021, 10:36am UTC](https://discuss.elastic.co/t/error-logstash-filters-ruby-ruby-exception-occurred-undefined-method-for-logstash-0x9a18b32/269301/2 "2021-04-06T10:36:43Z")

</div>

Hi,

To access to a field value in ruby filter, you have to do `event.get("field_name")`  
To edit a field value in ruby filter, you have to do `event.set("field_name", value)`

Gad

---

<div class="post-metadata">

**Author:** ![rumala](https://avatars.discourse-cdn.com/v4/letter/r/e56c9b/32.png) [@rumala](https://discuss.elastic.co/u/rumala)\
**Post date:** [April 8, 2021, 9:57am UTC](https://discuss.elastic.co/t/error-logstash-filters-ruby-ruby-exception-occurred-undefined-method-for-logstash-0x9a18b32/269301/3 "2021-04-08T09:57:12Z")

</div>

Hi, thank you, it works for me now

---

<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:** [May 6, 2021, 9:57am UTC](https://discuss.elastic.co/t/error-logstash-filters-ruby-ruby-exception-occurred-undefined-method-for-logstash-0x9a18b32/269301/4 "2021-05-06T09:57:45Z")

</div>

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