Logstash filter add new calculated float value

I've got Data from a Json Object and what i want is to calculate some Values of the same Object

   filter {
      json {
        source => "message"

	  mutate {
		add_field => { 
		"xxx1" => "Float(%{[BME680][Temperature]}*1.634*%{[BME680][Pressure]})"
                "xxx2" => "Float(%{[BME680][Temperature1]}*1.634*%{[BME680][Pressure1]})"
                "xxx3" => "Float(%{[xxx1]}-%{[xxx2]})"

The calculation is hier just for demo purposes - it's just multipling some fields and devide them.

The action should be that:
xxx1 should be calculated from some fields
xxx2 should be calculated from some fields
xxx3 should be calculated from both fields

ist this possible in logstash and how can it be done?

i only get the following

Aug 9, 2022 @ 14:13:39.104 Float(31.91.63410*993.0)

so i get the value as a String not as a number!

I would use ruby:

 ruby {
            code => "event.set('[xxx1]' , event.get('[BME680][Temperature]').to_f * 1.634 * event.get('[BME680][Pressure]').to_f )"

The '.to_f' in ruby converts those fields from string to float. Ideally that would be done earlier with mutate { convert => {"[BME680][Temperature]" => "float" }}.

Thank you, i'll give it a try and will report back soon!

Thank you very much, it works perfectly!

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