Creating Array in Logstash

I am looking to create an array in Logstash right now with an object inside of it.

Something that looks like this is what I am trying right now I am getting the error Ruby exception occurred: can't convert Array into String

event.set(["id_holder"], "[{ "uid": event.get([uid]), "id": event.get([id]) }]")

I am looking to make it similar to this
[ { "uid": 12423423423, "id": 6456456456 } ]

Is there a way to do this in logstash?

What you posted as an expected result is not really an array, more like a hash.
What you might be after is nested fields, which can easily be added with the mutate filter.

I need to have it wrapped in the array though, how would i get the hash to be wrapped in the array? Sorry I don't have much experience using the mutate filter and I am pretty confused with it.

Try this one, should produce what you are after.

    ruby {
        code => "
            event.set('id_holder', [Hash['uid',event.get('uid'),'id',event.get('id')]])

Example rubydebug output snippet

"id_holder" => [
    [0] {
        "uid" => "uid_value",
        "id" => "id_value"
1 Like

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