0

I'm try to create a array group by first column emp_no, I have this structure in a mysql table:

emp_no|salary|
------+------+
 10001| 60117|
 10001| 62102|
 10001| 66074|
 10001| 66596|
 10001| 66961|
 10001| 71046|
 10001| 74333|
 10001| 75286|

In logstash I tried aggregate filter using this configuration:

filter {
    aggregate {
    task_id => "%{emp_no}"
    code => "
      map['emp_no'] = event.get('emp_no')
      map['salaries'] ||= []
      map['salaries'] << {'salary' => event.get('salary')}
      event.cancel()
    "
    push_previous_map_as_event => true
    timeout => 3
    }
}

But this way I have this output:

{
  "emp_no": 10001,
  "salaries": [
    {
      "salary": 60117
    },
    {
      "salary": 62102
    },
    {
      "salary": 66074
    },
    {
      "salary": 66596
    },
    {
      "salary": 66961
    },
    {
      "salary": 71046
    },
    {
      "salary": 74333
    }
  ]
}

And I need this output, make an array called salaries that contains only salary values:

{
  "emp_no": 10001,
  "salaries": [
    60117,
    62102,
    66074,
    66596,
    66961,
    71046,
    ...,
  ]
}

1 Answer 1

1
map['salaries'] << {'salary' => event.get('salary')}

change this to

map['salaries'] << event.get('salary')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.