# Correct way to drop older events?

**URL:** https://discuss.elastic.co/t/correct-way-to-drop-older-events/131043
**Category:** Logstash
**Created:** [May 8, 2018, 5:09pm UTC](https://discuss.elastic.co/t/correct-way-to-drop-older-events/131043 "2018-05-08T17:09:28Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jonrust](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@jonrust](https://discuss.elastic.co/u/jonrust)
#### Post date: [May 8, 2018, 5:09pm UTC](https://discuss.elastic.co/t/correct-way-to-drop-older-events/131043/1 "2018-05-08T17:09:28Z")

</div>

I'd like to drop older events at logstash parsing time. Going with 100 days as my cutoff, I tried and failed to do this with the ruby module:

```
 ruby {
    code => "event.cancel if event.get(@timestamp) < (Time.now - (86400*100))"
 }

```

Is there a better way to do it? If not, what did i do wrong in the ruby code?

The error i see from LS is:

> [2018-05-08T13:10:58,506][ERROR][logstash.filters.ruby] Ruby exception occurred: no implicit conversion of nil into String

EDIT:

Better code? At least the errors have stopped.

```
ruby {
    code => "event.cancel if event.timestamp.to_i < (Time.now.to_i - (86400*10))"
}

```

---

<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: [May 8, 2018, 7:29pm UTC](https://discuss.elastic.co/t/correct-way-to-drop-older-events/131043/2 "2018-05-08T19:29:56Z")

</div>

The latter looks okay, but consider using the age filter.

---

<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: [June 5, 2018, 7:29pm UTC](https://discuss.elastic.co/t/correct-way-to-drop-older-events/131043/3 "2018-06-05T19:29:59Z")

</div>

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