Use gsub to add points to an integer

Hi all,
In my data stream i have a "price" value that however is an integer (1399 for 13.99 and so on). I want to convert it to ease the visualization but i can't find any valid numeral.js option in Kibana so i though of adding a new field during the Logstash pipeline, something like this:

  mutate {
    copy => { "[Price]" => "[PriceCent]" }
  }
  mutate {
    gsub => [ "[PriceCent]", "\d{2}$", "\.\d{2}$" ]
  }

However it isn't working. Am I missing something in the regex or I have to rethink all the process?
Thanks

You would need to use a capture group and reference it in the replacement.

In the end I solved the issue with another logic:

grok {
    match => {"[Price]" => "(?<units>\d*)(?<cents>\d{2})$"}
  }
 mutate {
    add_field => {
      "[PriceCent]" => "%{units},%{cents}"}
}

However i still do not grasp how to use gsub.

mutate { gsub => [ "[PriceCent]", "(\d{2})$", "\.\1" ]   }

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