Regex to integer\float

Hi,
I'm a little new to logstash.
I'm trying to figure out if there is a way to convert fields that match specific regex to integer:
i thought i could do it with grok but something there is not very clear to me.

use case:
if field name starts with n_ -> convert value to integer
if field name starts with f_ -> convert value to float
else leave it as string

thanks in advance.

Hello,

are the "n_" and "f_" sequences present anywhere else in your field names?

If not, you can just test if your field name contains one or the other sequence and then apply the mutate{ convert =>... } to your fields. I should be possible, all that is required is the right condition for the if

Hope this will help

See this response from earlier this morning:

Worked perfectly. thanks.

Hey Boris, which route did you end up going with? I'm challenged with a similar situation

edit: the ruby filter will work well for this. However, as of logstash 5.x directly editing a fields value is not allowed. I instead had to do this:

event.set(k, v.to_f) if k.start_with? 'metric-'