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

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?

1 Like

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

1 Like

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) ?


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).

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