# Aggregate plugin + event.get('@timestamp')

**URL:** <https://discuss.elastic.co/t/aggregate-plugin-event-get-timestamp/109945>\
**Category:** Logstash\
**Created:** [December 1, 2017, 2:30pm UTC](https://discuss.elastic.co/t/aggregate-plugin-event-get-timestamp/109945 "2017-12-01T14:30:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![wsteven](https://avatars.discourse-cdn.com/v4/letter/w/3d9bf3/32.png) [@wsteven](https://discuss.elastic.co/u/wsteven)\
**Post date:** [December 1, 2017, 2:30pm UTC](https://discuss.elastic.co/t/aggregate-plugin-event-get-timestamp/109945/1 "2017-12-01T14:30:44Z")

</div>

Hello there,  
I must be doing it wrong 🙂

```
   aggregate {
        task_id => "%{clientip}"
        code => "map['timestamp'] ||= event.get['@timestamp'].to_i"
        push_map_as_event_on_timeout => true
        timeout_task_id_field => "clientip"
        timeout => 14400
        inactivity_timeout => 600
        timeout_tags => ['_aggregatetimeout']
        timeout_code => "event.set('session_duration', map['timestamp'] - event.get['@timestamp'].to_i)"
    }

```

Throws me a:

```
[ERROR][logstash.filters.aggregate] Aggregate exception occurred {:error=>#<ArgumentError: wrong number of arguments calling `get` (0 for 1)>, :code=>"map['timestamp'] ||= event.get['@timestamp'].to_i", :map=>{}         

```

Can't find out what's wrong. The idea being to catch the timestamp from first event and compute difference with last event.

BTW, Logstash 5.5.0  
Thanks for any help!

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [December 5, 2017, 6:39am UTC](https://discuss.elastic.co/t/aggregate-plugin-event-get-timestamp/109945/2 "2017-12-05T06:39:23Z")

</div>

It's `event.get(...)`, not `event.get[...]`.

---

<div class="post-metadata">

**Author:** ![wsteven](https://avatars.discourse-cdn.com/v4/letter/w/3d9bf3/32.png) [@wsteven](https://discuss.elastic.co/u/wsteven)\
**Post date:** [December 5, 2017, 6:54am UTC](https://discuss.elastic.co/t/aggregate-plugin-event-get-timestamp/109945/3 "2017-12-05T06:54:49Z")

</div>

Oh god.  
Thanks Magnus.

---

<div class="post-metadata">

**Author:** ![Jon\_D](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jon_d/32/25657_2.png) [@Jon\_D](https://discuss.elastic.co/u/Jon_D)\
**Post date:** [December 13, 2017, 4:09pm UTC](https://discuss.elastic.co/t/aggregate-plugin-event-get-timestamp/109945/4 "2017-12-13T16:09:26Z")

</div>

Hi Magnus,

which kind of code is this? Is there a syntax description for it somewhere?

Thanks,  
regards,  
Jonas

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [December 13, 2017, 7:17pm UTC](https://discuss.elastic.co/t/aggregate-plugin-event-get-timestamp/109945/5 "2017-12-13T19:17:27Z")

</div>

> which kind of code is this?

Ruby.

> Is there a syntax description for it somewhere?

The Ruby language is of course well known and the Logstash event API is described at [Event API | Logstash Reference [8.11] | Elastic](https://www.elastic.co/guide/en/logstash/current/event-api.html).

---

<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:** [January 10, 2018, 7:18pm UTC](https://discuss.elastic.co/t/aggregate-plugin-event-get-timestamp/109945/6 "2018-01-10T19:18:05Z")

</div>

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