Unable to convert a field from string to integer that is dynamically generated in Logstash filter

I am adding a field in my event data point in Logstash filter. The name of the field is created dynamically based on the value of the other field. The code can be seen below which I am using to add this field

mutate {
    add_field =>  { "[data][queue-average-length][%{[data][queue-average-length][unit]}]" => "%{[data][queue-average-length][value]}"}    
}

Actually, I am trying to add a field in data.queue-average-length object and the name of the newly added field will be decided based on the value that is present in the data.queue-average-length.unit field. The value that is stored in newly created field is string but it contains an integer and I want to convert in into integer. In the next step, I used this code to convert string value to integer but I am getting _mutate_error tag.

mutate {
    convert => {"[data][queue-average-length][%{[data][queue-average-length][unit]}]" => "integer" }
}

If in the above code, instead of this expression %{[data][queue-average-length][unit]} I hardcode the value that is present in this field data.queue-average-length.unit, I do not get any error and value is successfully converted into integer. Can anyone guide me in this regard? Thanks

See this post. You cannot use a sprintf reference in the source of a convert.

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