Ruby to combine Object Array

Need Help with ruby code ( I have no knowledge with ruby) on how to combine nested array objects as one Dict ? , as I am facing issues with elastic getting"Object in arrays are not well supported Error" ,

Also I tried "nested" with "mapping" and mutate - convert but nothing seems to help

Input Data:
{
_"timestamp" : "1315294917923", _
"layers" : {
"data": [
{"type": "8","seq": "1"},
{"fixed_value": "","fixed_timestamp": "0x000000000001"}
]
} }

I want the final data uploaded to elastic to be as

{
_"timestamp" : "1315294917923", _
"layers" : {
"data": {"type": "8","seq": "1", "fixed_value": "","fixed_timestamp": "0x000000000001"
}
}

the "data" from a list is combined and converted as one Dict. Any input would be of great help

That should do it

filter {
  ruby {
    code => "
      event.set('[layers][data]', Hash[*event.get('[layers][data]').map(&:to_a).flatten])
    "
  }
}

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