I am using logstash with input jdbc, and would like to embed one object inside another with aggregate. How can I use add recursive?
Ie add an object inside another object?
My jdbc input would return output similar (as an example) to the following image:
This would be an example of how I want its output to be in elasticsearch. I describe the example for a single document, this should apply to the rest of the input data (id = 2, id = 3, etc):
{
"_index": "my-index",
"_type": "test",
"_id": "1",
"_version": 1,
"_score": 1,
"_source": {
"id": "1",
"properties": {
"id": "1",
"description": "Texto 1",
"Detail": [
{
"id_2": "1",
"cod": "A",
"descr": "Detail A",
"SubDetail": [
{
"id_3": "1",
"cod": "X1",
"descr": "Sub Detail X1"
}
]
},
{
"id_2": "2",
"cod": "B",
"descr": "Detail B",
"SubDetail": [
{
"id_3": "1",
"cod": "X1",
"descr": "Sub Detail X1"
},
{
"id_3": "2",
"cod": "X2",
"descr": "Sub Detail X2"
},
{
"id_3": "3",
"cod": "X3",
"descr": "Sub Detail X3"
}
]
}
]
}
}
}
In the filter section, I am using something like this but it is not working for me:
aggregate {
task_id => "%{id}"
code => "
map['id'] = event.get('id')
map['description'] = event.get('description')
map['detail_list'] ||= []
map['Detail'] ||= []
if (event.get('id_2') != nil)
if !( map['detail_list'].include?event.get('id_2') )
map['detail_list'] << event.get('id_2')
map['Detail'] << {
'id_2' => event.get('id_2'),
'cod' => event.get('cod_2'),
'descr' => event.get('descr_2'),
map['sub_detail_list'] ||= []
map['subDetail'] ||= []
if (event.get('id_3') != nil)
if !( map['sub_detail_list'].include?event.get('id_3') )
map['sub_detail_list'] << event.get('id_3')
map['subDetail'] << {
'id_3' => event.get('id_3'),
'cod' => event.get('cod_3'),
'descr' => event.get('descr_3')
}
end
end
}
end
end
event.cancel()
"
push_previous_map_as_event => true
timeout => 3
}
Any ideas or suggestions on how to implement something like this? I also clarify that I have configured pipeline.worker = 1.