# Check if event field does not exist when 'nil' should be considered as "exists"

**URL:** https://discuss.elastic.co/t/check-if-event-field-does-not-exist-when-nil-should-be-considered-as-exists/284605
**Category:** Logstash
**Created:** [September 20, 2021, 8:48am UTC](https://discuss.elastic.co/t/check-if-event-field-does-not-exist-when-nil-should-be-considered-as-exists/284605 "2021-09-20T08:48:45Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![e.sharshenaliev](https://avatars.discourse-cdn.com/v4/letter/e/779978/32.png) [@e.sharshenaliev](https://discuss.elastic.co/u/e.sharshenaliev)
#### Post date: [September 20, 2021, 8:48am UTC](https://discuss.elastic.co/t/check-if-event-field-does-not-exist-when-nil-should-be-considered-as-exists/284605/1 "2021-09-20T08:48:45Z")

</div>

We are indexing metrics that arrive to logstash in json format  
There is a value "MeasurementDate" that can either:

1. be missing
2. has null value
3. has date value (iso8601)

When field has valid value or is missing - we need to index this event  
When field has value of null - we need to drop this event

Is there any way to differentiate between missing field and field with a value of null/nil?

---

<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: [September 20, 2021, 1:09pm UTC](https://discuss.elastic.co/t/check-if-event-field-does-not-exist-when-nil-should-be-considered-as-exists/284605/2 "2021-09-20T13:09:29Z")

</div>

> [@e.sharshenaliev](#):
>
> Is there any way to differentiate between missing field and field with a value of null/nil?

You cannot do it using a conditional, but you can do it in ruby

```
    ruby {
        code => '
            if event.to_hash.include?("foo") and ! event.get("foo")
                event.cancel
            end
        '
    }

```

---

<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: [October 18, 2021, 1:09pm UTC](https://discuss.elastic.co/t/check-if-event-field-does-not-exist-when-nil-should-be-considered-as-exists/284605/3 "2021-10-18T13:09:30Z")

</div>

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