# Duration calculation failing

**URL:** <https://discuss.elastic.co/t/duration-calculation-failing/169411>\
**Category:** Logstash\
**Created:** [February 21, 2019, 12:47pm UTC](https://discuss.elastic.co/t/duration-calculation-failing/169411 "2019-02-21T12:47:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rudolf\_Reddy\_Macejka](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rudolf_reddy_macejka/32/12875_2.png) [@Rudolf\_Reddy\_Macejka](https://discuss.elastic.co/u/Rudolf_Reddy_Macejka)\
**Post date:** [February 21, 2019, 12:47pm UTC](https://discuss.elastic.co/t/duration-calculation-failing/169411/1 "2019-02-21T12:47:31Z")

</div>

Hello,

I am trying to calculate duration by grog and inspirated by another topis here.  
So I have this code:

```
  date {
    match => ["time","UNIX_MS"]
    target => "@timestamp"
    remove_field => ["time"]
  }

  mutate {
    add_field => { "[request][time]" => "%{@timestamp}" }
  }

  date {
    match => ["[legs][0][timestamp]","UNIX_MS" ]
    target => "[response][time]"
  }

  ruby {
    code => "event['durationNew'] = Time.parse(event['[response][time]'] - event['[request][time]'])"
  }

```

But I am getting this error:  
`[2019-02-21T13:31:27,726][ERROR][logstash.filters.ruby] Ruby exception occurred: Direct event field references (i.e. event['field']) have been disabled in favor of using event get and set methods (e.g. event.get('field')). Please consult the Logstash 5.0 breaking changes documentation for more details.`

Any idea what is wrong?

Thanks and Regards, Reddy

---

<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 21, 2019, 2:09pm UTC](https://discuss.elastic.co/t/duration-calculation-failing/169411/2 "2019-02-21T14:09:19Z")

</div>

> [@Rudolf\_Reddy\_Macejka](#):
>
> "event['durationNew'] = Time.parse(event['[response][time]'] - event['[request][time]'])"

This should be

```
"event.set('durationNew', Time.parse(event.get('[response][time]') - event.get('[request][time]')))"

```

---

<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 21, 2019, 2:09pm UTC](https://discuss.elastic.co/t/duration-calculation-failing/169411/3 "2019-03-21T14:09:25Z")

</div>

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