I would like to ask With reference to the following where there is a parent-child relation is pipelined
Logstash aggregate-example4
I wonder how to achieve a scenario where event elements have a hierarchal relationship like following
parent (n)
---child (n)
------ grand-child (n)
------------great-grand-child (n)
For events, I am using JDBC and a SQL query. works fine and giving me events as expected
I filter aggregate them with the following code.
filter {
aggregate {
task_id => "%{region_name}"
code => "
map['region_name'] = event.get('region_name')
map['countryz_lst'] ||= []
map['countryz'] ||= []
if (event.get('country_name') != nil)
if !( map['countryz_lst'].include? event.get('country_name') )
map['countryz_lst'] << event.get('country_name')
map['countryz'] << {
'country_name' => event.get('country_name')
}
end
map['cityz_lst'] ||= []
map['cityz'] ||= []
if (event.get('city') != nil)
if !( map['cityz_lst'].include? event.get('city') )
map['cityz_lst'] << event.get('city')
map['cityz'] << {
'city' => event.get('city'),
'postal_code' => event.get('postal_code')
}
end
end
event.cancel()
end
event.cancel()
"
push_map_as_event_on_timeout => true
timeout => 123
}
mutate {
remove_field => ["countryz_lst","cityz_lst","@version","@timestamp"]
}
}
output {
# Output to the console.
stdout {
codec => json_lines
}
}
It produces the following json
{
"region_name": "Europe",
"countryz": [
{
"country_name": "United Kingdom"
},
{
"country_name": "Netherlands"
},
{
"country_name": "Italy"
},
{
"country_name": "France"
},
{
"country_name": "Denmark"
},
{
"country_name": "Germany"
},
{
"country_name": "Switzerland"
},
{
"country_name": "Belgium"
}
],
"cityz": [
{
"postal_code": "09629850293",
"city": "Stretford"
},
{
"postal_code": "OX9 9ZB",
"city": "Oxford"
},
{
"postal_code": null,
"city": "London"
},
{
"postal_code": "3029SK",
"city": "Utrecht"
},
{
"postal_code": "10934",
"city": "Venice"
},
{
"postal_code": "00989",
"city": "Roma"
},
{
"postal_code": "80925",
"city": "Munich"
},
{
"postal_code": "3095",
"city": "Bern"
},
{
"postal_code": "1730",
"city": "Geneva"
}
]
}
REGION
COUNTRY
CITY
I want related cities nested into related countries.
Like
Region
COUNTRY
CITY
I hope i could explain.
Thanks in advance