# Logstash 2.4.0: Ruby exception occurred: undefined method \`/'

**URL:** https://discuss.elastic.co/t/logstash-2-4-0-ruby-exception-occurred-undefined-method/107070
**Category:** Logstash
**Created:** [November 9, 2017, 4:48pm UTC](https://discuss.elastic.co/t/logstash-2-4-0-ruby-exception-occurred-undefined-method/107070 "2017-11-09T16:48:08Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![AlessandroC985](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@AlessandroC985](https://discuss.elastic.co/u/AlessandroC985)
#### Post date: [November 9, 2017, 4:48pm UTC](https://discuss.elastic.co/t/logstash-2-4-0-ruby-exception-occurred-undefined-method/107070/1 "2017-11-09T16:48:08Z")

</div>

I'm trying to modify the value of a numeric field (type long) with logstash 2.4.0 using the ruby filter.

This is my filter configuration:

```
ruby {
    code => "event.set('myField', event.get('myField') / 1000)"
}

```

I have the following error:

{:timestamp=\>"2017-11-09T16:17:38.511000+0000", :message=\>"Ruby exception occurred: undefined method `/' for "414886000":String", :level=\>:error}

The "myField" field is correctly stored in elasticsearch, but it's not divided.

What's wrong?  
Thanks.

---

<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: [November 9, 2017, 4:49pm UTC](https://discuss.elastic.co/t/logstash-2-4-0-ruby-exception-occurred-undefined-method/107070/2 "2017-11-09T16:49:43Z")

</div>

The `myField` field is a string. Replace `event.get('myField')` with `event.get('myField').to_i`.

---

<div class="post-metadata">

### Author: ![AlessandroC985](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@AlessandroC985](https://discuss.elastic.co/u/AlessandroC985)
#### Post date: [November 9, 2017, 4:56pm UTC](https://discuss.elastic.co/t/logstash-2-4-0-ruby-exception-occurred-undefined-method/107070/3 "2017-11-09T16:56:08Z")

</div>

Perfect! That has solved the issue!

Just a curiosity: "myField" is stored as a "long" field in elasticsearch.  
This means that in logstash is still a "String" type (before being pushed to Elasticsearch) ?

Thanks!

---

<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: [November 9, 2017, 9:42pm UTC](https://discuss.elastic.co/t/logstash-2-4-0-ruby-exception-occurred-undefined-method/107070/4 "2017-11-09T21:42:07Z")

</div>

Yes. The type of the field in ES and the type of the corresponding field in the JSON document don't have to be equal, but a string value in the document can definitely be mapped as an integer (as long as the string can be parsed as an integer obviously).

---

<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: [December 7, 2017, 9:42pm UTC](https://discuss.elastic.co/t/logstash-2-4-0-ruby-exception-occurred-undefined-method/107070/5 "2017-12-07T21:42:10Z")

</div>

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