Logstash JSON代码和Ruby没有正确处理小数(浮点)



我有Kafak<gt;Logstash(然后是Ruby(<gt;弹性

Kafak输入:

{"customerid":"smit","last_name":"shah","age":10,"height":10,"weight":100,"automated_email":false, "header": { "endpoint":"/pay"}, "transaction": { "amount":100.50, "currency" : "SGD"}}

Logstash:

json {
source => "message"
}
mutate {
convert => { "amount" => "float" }
}
ruby {
# Cancel 90% of events
path => "/usr/local/etc/logstash/main.rb"
script_params => { "percentage" => 0.9 }
}
}

Ruby

transaction = event.get('transaction')
puts transaction
puts transaction['amount']

此打印:

{"amount"=>0.1005e3, "currency"=>"SGD"}
0.1005e3

为什么我没有得到100.5?

尝试使用transaction['amount'].to_f

最新更新