How to add field to every element from an array with variable length

Hi experts,

I have an array such like this:
"NODE" : ["node1", "node2", "node3"]

And my first requirement is add field to every element from this array. I have used a hard code to add three fields for these three elements.

mutate {
                add_field => {
                                "container1" => "%{[NODE][1]}"
                                "container2" => "%{[NODE][2]}"
                                "container3" => "%{[NODE][3]}"

Then I can use them to do my retrieve work.
Now my major question is coming: actually the length of this array is variable! sometimes it may include more than 10 elements, that means I need wirte more than 10 line's redundancy code in my filter pattern. Are there some methods that can handle the variable length array that make the pattern code efficiently?

Thank you.

ruby { code => ' event.get("NODE").each_with_index { |x, i| event.set( "container#{i+1}" , x) } ' }

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