# Logstash aggregation overwrite

**URL:** https://discuss.elastic.co/t/logstash-aggregation-overwrite/274556
**Category:** Logstash
**Created:** [June 1, 2021, 12:42am UTC](https://discuss.elastic.co/t/logstash-aggregation-overwrite/274556 "2021-06-01T00:42:42Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![fuzes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fuzes/32/46820_2.png) [@fuzes](https://discuss.elastic.co/u/fuzes)
#### Post date: [June 1, 2021, 12:42am UTC](https://discuss.elastic.co/t/logstash-aggregation-overwrite/274556/1 "2021-06-01T00:42:42Z")

</div>

I don't know why aggregation is overwritten by last one  
following is my logstash code

```auto
filter {
  aggregate {
    task_id => "%{code}"
      code => "
        map['code'] = event.get('code')
        map[event.get('language')] ||= {
            'name' => event.get('name')
            ...
        }
      push_previous_map_as_event => true
      push_map_as_event_on_timeout => true
      timeout_task_id_field => "task_id"
      timeout => 3000
  }
  mutate {
    copy => { "code" => "[@metadata][_id]" }
    remove_field => ["code", "@version", "unix_ts_in_secs"]
  }
}

```

and following is mysql result...

mysql rows =  
["code" "language", "name"] = [[10345, "jp", "test1"], [10345, "th", "test2]]

i want to

```auto
jp: {
 name: "test1"
}
th: {
  name: "test2"
}

```

but result have always just last language data

```auto
th: {
   name: "test2"
}

```

i don't know why aggregation doesn't work well

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [June 1, 2021, 1:13am UTC](https://discuss.elastic.co/t/logstash-aggregation-overwrite/274556/2 "2021-06-01T01:13:42Z")

</div>

> [@fuzes](#):
>
> ```auto
> map[event.get('language')] ||= {
> 'name' => event.get('name')
> ...
> }
> 
> ```

That only sets map["10345"] if it is nil. I think what you want is

```
    map[event.get('language')] ||= []
    map[event.get('language')] << { 'name' => event.get('name') }

```

---

<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: [June 29, 2021, 1:14am UTC](https://discuss.elastic.co/t/logstash-aggregation-overwrite/274556/3 "2021-06-29T01:14:30Z")

</div>

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