# Help with Aggregate filter

**URL:** https://discuss.elastic.co/t/help-with-aggregate-filter/298167
**Category:** Logstash
**Created:** [February 24, 2022, 1:31pm UTC](https://discuss.elastic.co/t/help-with-aggregate-filter/298167 "2022-02-24T13:31:07Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![BhawanaSharma](https://avatars.discourse-cdn.com/v4/letter/b/7feea3/32.png) [@BhawanaSharma](https://discuss.elastic.co/u/BhawanaSharma)
#### Post date: [February 24, 2022, 1:31pm UTC](https://discuss.elastic.co/t/help-with-aggregate-filter/298167/1 "2022-02-24T13:31:07Z")

</div>

aggregate  
{  
timeout\_tags =\> ['\_aggregatetimeout']  
task\_id =\> "%{[log][file][path]}"   
code =\> 'map["build\_name"] = event.get("[build\_name\_long]") ; map["build\_link"] = event.get("[build\_name\_start]") ; event.set("build\_name", map["build\_name"])'   
map\_action =\> "create"  
push\_map\_as\_event\_on\_timeout =\> true  
add\_tag =\> ["start\_aggregate"]  
}

aggregate  
{  
task\_id =\> "%{[log][file][path]}"  
code =\> 'event.set("build\_name", map["build\_name"]) ; event.set("build\_link", map["build\_link"])'  
add\_tag =\> ["do\_aggregate"]  
}

Logstash version - 6.8.17  
I am trying to fetch build\_name\_long and build\_name\_start value from grok filter and those are coming correctly, but on second filter while trying to set those value to build\_name and build\_link fields name not getting correct results. Can anyone please help me on this?

---

<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: [February 24, 2022, 9:13pm UTC](https://discuss.elastic.co/t/help-with-aggregate-filter/298167/2 "2022-02-24T21:13:28Z")

</div>

If you run this configuration, what result do you get?

```
input { generator { count => 1 lines => ['{"id": 1, "a": 2}', '{"id": 1}'] codec => json } }
filter {
    aggregate {
        task_id => "%{[id]}"
        code => 'map["a"] = event.get("[a]")'
        map_action => "create"
        push_map_as_event_on_timeout => true
        timeout => 10
        add_tag => ["start_aggregate"]
    }
    aggregate {
        task_id => "%{[id]}"
        code => 'event.set("a", map["a"])'
        add_tag => ["do_aggregate"]
    }
}
output { stdout { codec => rubydebug { metadata => false } } }
```

---

<div class="post-metadata">

### Author: ![BhawanaSharma](https://avatars.discourse-cdn.com/v4/letter/b/7feea3/32.png) [@BhawanaSharma](https://discuss.elastic.co/u/BhawanaSharma)
#### Post date: [February 25, 2022, 6:58am UTC](https://discuss.elastic.co/t/help-with-aggregate-filter/298167/3 "2022-02-25T06:58:16Z")

</div>

Hello,  
Thanks for your help. I tried your suggested code and I am getting below result :  
{  
"sequence" =\> 0,  
"tags" =\> [  
[0] "start\_aggregate",  
[1] "do\_aggregate"  
],  
"@version" =\> "1",  
"id" =\> 1,  
"a" =\> 2,  
"host" =\> "VI281154",  
"@timestamp" =\> 2022-02-25T07:55:41.632Z  
}  
{  
"sequence" =\> 0,  
"tags" =\> [  
[0] "do\_aggregate"  
],  
"@version" =\> "1",  
"id" =\> 1,  
"a" =\> 2,  
"host" =\> "VI281154",  
"@timestamp" =\> 2022-02-25T07:55:41.647Z

---

<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: [February 25, 2022, 5:23pm UTC](https://discuss.elastic.co/t/help-with-aggregate-filter/298167/4 "2022-02-25T17:23:32Z")

</div>

That is what I would expect. In that case I cannot explain why your aggregates do not work the same way.

---

<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: [March 25, 2022, 5:23pm UTC](https://discuss.elastic.co/t/help-with-aggregate-filter/298167/5 "2022-03-25T17:23:58Z")

</div>

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