Ruby code calculate problem

Hello,we now want to do Arithmetic in logstash ruby code.

The ruby code is:

ruby {
init => "@@count = -1"
code => "
event.set('[test]', @@count)
event.set('[test2]', event.get('[layers][frame_time_relative]').to_f / 0.3)
@@count = event.get('[layers][frame_time_relative]')
"
}

The frame_time_relative is a float type number.

We find the "test2" event code function can not work.

Data in kibana only show "test1".

We set the test2 elasticsearch module as:"test2":{"type":"long","fields": {"keyword": {"ignore_above": 256,"type": "keyword"}}}

We try this module setting or use default setting the result is same.

Is there any wrong coding?

Please copy/paste the text instead of posting screenshots.

As the second screenshot shows the [layers][frame_time_relative] field is an array with a single element. To access it and convert it to a number you can do event.get('[layers][frame_time_relative]')[0].to_f.

It can works!

Thanks for your reply.

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