Hi, im formating a date string with the following code.
ruby {
code => '
time = event.get("fecha")
event.remove("fecha")
fe = Date.strptime(time, "%m/%d/%Y")
event.set("fecha", fe.strftime("%d/%m/%Y"))
'
}
the code works, but at the beggining of the rubydebug output, gives me multiple lines with this error:
Ruby exception occurred: class org.jruby.RubyNil cannot be cast to class org.jruby.RubyString (org.jruby.RubyNil and org.jruby.RubyString are in unnamed module of loader 'app')
as Wolfram said, some of the processed documents might don't have the fecha field assigned. It is a good practice to check for the existence of a given field before working with it. Try something like this:
Why should you get a _grokparsefailure without applying a grok filter?
You're applying a Ruby filter, not a grok. And when you try to get the fecha field on a document which doesn't have it, you're assigning the value nil to the variable time. Then, you're trying to apply a string method to that nil value, so it raises an exception.
Can you post here the sample message that doesn't return a fecha field and the grok filter you're applying before the ruby (or also your whole pipeline)?
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.