Logstash: NoMethodError: method `>=' for nil:NilClass

Hello everyone,

Here is my configuration file:
input {
stdin { }
file {
path => ["myfile.json"]
type => "bytel"
codec => "json"
}
}

filter {

if [log][Frequency] != [] {
    if [log][Frequency] >= 866.0 {
        mutate {
            add_field => ["[log][subband]", "7"] 
        }
   }
}

}

output {
elasticsearch {
hosts => ["localhost:9200"]
index => "test"
}
stdout { codec => rubydebug }
}

I got the folloing error :
Exception in pipelineworker, the pipeline stopped processing new events, please check your filter configuration and restart Logstash. {"exception"=>#<NoMethodError: undefined method >=' for nil:NilClass>, "backtrace"=>["(eval):177:incond_func_4'", "org/jruby/RubyArray.java:1613:in each'", "(eval):175:incond_func_4'", "(eval):192:in cond_func_3'", "org/jruby/RubyArray.java:1613:ineach'", "(eval):189:in cond_func_3'", "(eval):131:infilter_func'", "/home/sagemcom/ELK/logstash-2.2.4/vendor/bundle/jruby/1.9/gems/logstash-core-2.2.4-java/lib/logstash/pipeline.rb:259:in filter_batch'", "org/jruby/RubyArray.java:1613:ineach'", "org/jruby/RubyEnumerable.java:852:in inject'", "/home/sagemcom/ELK/logstash-2.2.4/vendor/bundle/jruby/1.9/gems/logstash-core-2.2.4-java/lib/logstash/pipeline.rb:257:infilter_batch'", "/home/sagemcom/ELK/logstash-2.2.4/vendor/bundle/jruby/1.9/gems/logstash-core-2.2.4-java/lib/logstash/pipeline.rb:215:in worker_loop'", "/home/sagemcom/ELK/logstash-2.2.4/vendor/bundle/jruby/1.9/gems/logstash-core-2.2.4-java/lib/logstash/pipeline.rb:193:instart_workers'"], :level=>:error}
Exception in pipelineworker, the pipeline stopped processing new events, please check your filter configuration and restart Logstash. {"exception"=>#<NoMethodError: undefined method >=' for nil:NilClass>, "backtrace"=>["(eval):177:incond_func_4'", "org/jruby/RubyArray.java:1613:in each'", "(eval):175:incond_func_4'", "(eval):192:in cond_func_3'", "org/jruby/RubyArray.java:1613:ineach'", "(eval):189:in cond_func_3'", "(eval):131:infilter_func'", "/home/sagemcom/ELK/logstash-2.2.4/vendor/bundle/jruby/1.9/gems/logstash-core-2.2.4-java/lib/logstash/pipeline.rb:259:in filter_batch'", "org/jruby/RubyArray.java:1613:ineach'", "org/jruby/RubyEnumerable.java:852:in inject'", "/home/sagemcom/ELK/logstash-2.2.4/vendor/bundle/jruby/1.9/gems/logstash-core-2.2.4-java/lib/logstash/pipeline.rb:257:infilter_batch'", "/home/sagemcom/ELK/logstash-2.2.4/vendor/bundle/jruby/1.9/gems/logstash-core-2.2.4-java/lib/logstash/pipeline.rb:215:in worker_loop'", "/home/sagemcom/ELK/logstash-2.2.4/vendor/bundle/jruby/1.9/gems/logstash-core-2.2.4-java/lib/logstash/pipeline.rb:193:instart_workers'"], :level=>:error}
NoMethodError: undefined method `>=' for nil:NilClass
cond_func_4 at (eval):177
each at org/jruby/RubyArray.java:1613
cond_func_4 at (eval):175
cond_func_3 at (eval):192
each at org/jruby/RubyArray.java:1613
cond_func_3 at (eval):189
filter_func at (eval):131

Do you how to solve this problem please ?!!

Thank you for your attention and your help.

S

So I'm not 100% why this is but it seems that you need to add this before you do the comparison:

mutate {
convert => { "[log][Frequency]" => "integer" }
}

My guess is that Logstash is reading that field as a string and the error is being thrown because it can't compare a String to an Integer. It just needs to be converted from a String to an Integer.

The line

if [log][Frequency] != [] {

probably checks if the field in question is equal to an empty array, which it isn't, so it continues with the next conditional. You probably want to check if the field is defined:

if [log][Frequency] {
1 Like

it works. Thank you !