# Push logstash aggregate map as fields in final event

**URL:** <https://discuss.elastic.co/t/push-logstash-aggregate-map-as-fields-in-final-event/290929>\
**Category:** Logstash\
**Created:** [December 3, 2021, 7:17pm UTC](https://discuss.elastic.co/t/push-logstash-aggregate-map-as-fields-in-final-event/290929 "2021-12-03T19:17:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joe\_Martin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joe_martin/32/98140_2.png) [@Joe\_Martin](https://discuss.elastic.co/u/Joe_Martin)\
**Post date:** [December 3, 2021, 7:17pm UTC](https://discuss.elastic.co/t/push-logstash-aggregate-map-as-fields-in-final-event/290929/1 "2021-12-03T19:17:40Z")

</div>

I am trying to use an aggregate filter to pull fields from several different but related logs into one "summary" log. There is a clear end\_of\_task event and I would like to "push"/add all of the fields in the map into the final end\_of\_task event.

Do I have to use a "event.set" command for each of the possible fields in the map?  
`event.set('field1', map['field1'])`  
I would prefer NOT to use this route as the number and names of the fields in the map can vary.  
OR  
Can I iterate through all the fields in the map in some way?  
OR  
Can I just push the whole map into the event as an array with event.set?  
Something like this `event.set('session_summary', map)`?

---

<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:** [December 3, 2021, 7:58pm UTC](https://discuss.elastic.co/t/push-logstash-aggregate-map-as-fields-in-final-event/290929/2 "2021-12-03T19:58:52Z")

</div>

> [@Joe\_Martin](#):
>
> Can I iterate through all the fields in the map in some way?

Yes, you could do

```
    aggregate {
        task_id => "%{task}"
        map_action => "update"
        end_of_task => true
        code => 'map.each { |k, v| event.set(k, v) }'
    }

```

You might also be able to do it using the push\_previous\_map\_as\_event option, but that would depend on your data.

---

<div class="post-metadata">

**Author:** ![Joe\_Martin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joe_martin/32/98140_2.png) [@Joe\_Martin](https://discuss.elastic.co/u/Joe_Martin)\
**Post date:** [December 3, 2021, 8:12pm UTC](https://discuss.elastic.co/t/push-logstash-aggregate-map-as-fields-in-final-event/290929/3 "2021-12-03T20:12:06Z")

</div>

Thanks @Badger!

Your comment about "push\_previous\_map\_as event" produced another question, as this is my first time using the aggregate filter.  
Due to the nature of my logs, it is very likely that I will have multiple maps being handled at the same time. My understanding of the "push\_previous\_map\_as\_event" is that it would push the previous map (and all associated data/fields) out of memory as soon as it saw a log with a different "task\_id".  
Is this correct?  
And/or am I wrong in my understanding that this filter can handle multiple simultaneous maps?

---

<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:** [December 3, 2021, 8:39pm UTC](https://discuss.elastic.co/t/push-logstash-aggregate-map-as-fields-in-final-event/290929/4 "2021-12-03T20:39:54Z")

</div>

> [@Joe\_Martin](#):
>
> My understanding of the "push\_previous\_map\_as\_event" is that it would push the previous map (and all associated data/fields) out of memory as soon as it saw a log with a different "task\_id".

That is my understanding of it too.

---

<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:** [December 31, 2021, 8:40pm UTC](https://discuss.elastic.co/t/push-logstash-aggregate-map-as-fields-in-final-event/290929/5 "2021-12-31T20:40:29Z")

</div>

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