# Grok fiels are removed by aggregate section

**URL:** <https://discuss.elastic.co/t/grok-fiels-are-removed-by-aggregate-section/324798>\
**Category:** Logstash\
**Created:** [February 6, 2023, 2:15pm UTC](https://discuss.elastic.co/t/grok-fiels-are-removed-by-aggregate-section/324798 "2023-02-06T14:15:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Miriam](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@Miriam](https://discuss.elastic.co/u/Miriam)\
**Post date:** [February 6, 2023, 2:15pm UTC](https://discuss.elastic.co/t/grok-fiels-are-removed-by-aggregate-section/324798/1 "2023-02-06T14:15:24Z")

</div>

I have follwoing file structure:

```auto
id, iduser,datetimInit, dateTimeends
0001 0001 2023-02-03 04:45:16.78 2023-02-03 04:46:16.78
0002 0001 2023-02-03 08:45:16.78 2023-02-03 08:46:16.78
0003 0002 2023-02-04 04:45:16.78 2023-02-04 04:46:16.78

```

Where: I need to add duration time (datetimeEnds - dateTimeInit) , and full duration (sum duration by idUser) time by iduser. i have the following configuration file:

```auto
filter {	
	grok {
		match => { 
			"message" => "%{NUMBER:id} %{NUMBER:idUser} %{TIMESTAMP_ISO8601:dateTimeInit} %{TIMESTAMP_ISO8601:dateTimeEnds}" 
		}
	}
	date { match => ["dateTimeInit", "ISO8601"] target => "dateTimeInit" }
	date { match => ["dateTimeEnds", "ISO8601"] target => "dateTimeEnds" }
	
	#add duration by row
	ruby { 
		code => "event.set('duration', event.get('dateTimeEnds').to_i - event.get('dateTimeInit').to_i); "
	}
	
	#add fullduration depending on same iduser
	aggregate {
       task_id => "%{idUser}"
       code => "
			map['full_duration'] ||= 0 ; 
			map['full_duration'] += event.get('duration')
			event.cancel()
		"
	   push_previous_map_as_event => true
       timeout => 3
    }
}

```

This is the output:

```auto
{
    "full_duration" => 2,
       "@timestamp" => 2023-02-06T13:08:18.923849100Z,
         "@version" => "1"
}

```

Where Dates and idUser fields are missing.

How could I add all the fields to the output, not just full\_duration?

Thank you in advance

---

<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 6, 2023, 5:54pm UTC](https://discuss.elastic.co/t/grok-fiels-are-removed-by-aggregate-section/324798/2 "2023-02-06T17:54:09Z")

</div>

> [@Miriam](#):
>
> `push_previous_map_as_event => true`

That pushes the previous map as an event. The only field you added to the map is map['full\_duration'], so that is the only non-standard field that your event has. You need to copy the other fields that you want to preserve to fields in the map hash.

---

<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 6, 2023, 5:54pm UTC](https://discuss.elastic.co/t/grok-fiels-are-removed-by-aggregate-section/324798/3 "2023-03-06T17:54:55Z")

</div>

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