Logstash substring a field using position getting error

Hello Everyone,
I am getting below error while trying to produce new event from existing one as follows, any help?

    ruby { code => "event['new_field'] = event.get['dummy'][1..4]" }

Error:

Ruby exception occurred: undefined method []' for nil:NilClass {:class=>"NoMethodError", :backtrace=>["(ruby filter code):2:in block in filter_method'", "./LOGSTASH/logstash-7.16.1/vendor/bundle/jruby/2.5.0/gems/logstash-filter-ruby-3.1.7/lib/logstash/filters/ruby.rb:93:in inline_script'", "./LOGSTASH/logstash-7.16.1/vendor/bundle/jruby/2.5.0/gems/logstash-filter-ruby-3.1.7/lib/logstash/filters/ruby.rb:86:in filter'", "./LOGSTASH/logstash-7.16.1/logstash-core/lib/logstash/filters/base.rb:159:in do_filter'", "./LOGSTASH/logstash-7.16.1/logstash-core/lib/logstash/filters/base.rb:178:in block in multi_filter'", "org/jruby/RubyArray.java:1821:in each'", "/evam/LOGSTASH/logstash-7.16.1/logstash-core/lib/logstash/filters/base.rb:175:in multi_filter'", "org/logstash/config/ir/compiler/AbstractFilterDelegatorExt.java:134:in multi_filter'", "./LOGSTASH/logstash-7.16.1/logstash-core/lib/logstash/java_pipeline.rb:299:in block in start_workers'"]}

sample conf:

input {
        stdin { id => "inPut" }
}
filter{
        ruby { code => "event['new_field'] = event.get['dummy'][1..4]" }
}
output {
        stdout { codec => rubydebug }
}

That is telling you that the [dummy] field does not exist, so event.get returns nil, and an attempt to extract a substring of nil fails.

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