# Logstash - Nested aggregation

**URL:** https://discuss.elastic.co/t/logstash-nested-aggregation/280308
**Category:** Logstash
**Created:** [August 3, 2021, 12:23pm UTC](https://discuss.elastic.co/t/logstash-nested-aggregation/280308 "2021-08-03T12:23:28Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![MattQDev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattqdev/32/77073_2.png) [@MattQDev](https://discuss.elastic.co/u/MattQDev)
#### Post date: [August 3, 2021, 12:23pm UTC](https://discuss.elastic.co/t/logstash-nested-aggregation/280308/1 "2021-08-03T12:23:28Z")

</div>

Hey,

I am trying to aggregate some data from a SQL DB with Logstash. The data that I am trying to import has the following structure:

- Category
- 
  - Type

- 
  - 
    - Product

Where each category can have multiple types, and each type can have multiple products

The data is read line by line as:  
categoryid | categoryname | typeid | typename | productid | productname

The code I currently have is as follows:

```auto
filter {
 aggregate {
   task_id => "%{categoryid}"
   code => "
	 map['categoryid'] = event.get('categoryid')
	 map['categoryname'] = event.get('categoryname')
	 map['types'] ||= []
	 map['types'] << {
		'typeid' => event.get('typeid'),
		'typename' => event.get('typename'),
	 }
	map['types']['products'] ||= []
	map['types']['products'] << {
		'productid' => event.get('productid'),
        'productname' => event.get('productname')
	}
	
	 event.cancel()
   "
   push_previous_map_as_event => true
   timeout => 3
 }
}

```

Unfortunately, this code doesn't work and gives a 'String to Integer' conversion error

I've been searching for help around, but can't seem to find an answer that works.  
Thanks in advance!

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [August 31, 2021, 12:23pm UTC](https://discuss.elastic.co/t/logstash-nested-aggregation/280308/2 "2021-08-31T12:23:30Z")

</div>

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