# Using Prune Filter To Remove Null Value Fields

**URL:** <https://discuss.elastic.co/t/using-prune-filter-to-remove-null-value-fields/191659>\
**Category:** Logstash\
**Created:** [July 22, 2019, 2:29pm UTC](https://discuss.elastic.co/t/using-prune-filter-to-remove-null-value-fields/191659 "2019-07-22T14:29:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wwalker](https://avatars.discourse-cdn.com/v4/letter/w/43a26b/32.png) [@wwalker](https://discuss.elastic.co/u/wwalker)\
**Post date:** [July 22, 2019, 2:29pm UTC](https://discuss.elastic.co/t/using-prune-filter-to-remove-null-value-fields/191659/1 "2019-07-22T14:29:41Z")

</div>

I am using the JSON filter to parse out events. However, many fields are frequently blank. I'd like to remove those fields without having to manually specify `if blank then use mutate to remove field` dozens of times. It looks like the prune filter would work for me but I wanted to double-check before I implement. Is the below config all I would need to accomplish this?

```auto
prune {
  blacklist_values => [""]
}

```

---

<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:** [July 22, 2019, 2:43pm UTC](https://discuss.elastic.co/t/using-prune-filter-to-remove-null-value-fields/191659/2 "2019-07-22T14:43:25Z")

</div>

No, blacklist\_values takes a hash, each member of which is a field name and a regexp used to determine whether to remove the field. You can do it in ruby

```
    ruby {
        code => '
            event.to_hash.each { |k, v|
                if v.kind_of? String
                    if v == ""
                        event.remove(k)
                    end
                end
            }
        '
    }
```

---

<div class="post-metadata">

**Author:** ![wwalker](https://avatars.discourse-cdn.com/v4/letter/w/43a26b/32.png) [@wwalker](https://discuss.elastic.co/u/wwalker)\
**Post date:** [July 22, 2019, 3:05pm UTC](https://discuss.elastic.co/t/using-prune-filter-to-remove-null-value-fields/191659/3 "2019-07-22T15:05:44Z")

</div>

Gotcha....that's a weird syntax that prune is using, or at least different from what I've seen other hash values look like.

Regarding the ruby code you entered, does the string `event.to_hash.each` need to be changed or am I copy/pasting exactly what you have into my pipeline?

---

<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:** [July 22, 2019, 3:14pm UTC](https://discuss.elastic.co/t/using-prune-filter-to-remove-null-value-fields/191659/4 "2019-07-22T15:14:18Z")

</div>

If you are removing fields from the top-level then it will work as is.

---

<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:** [August 19, 2019, 3:29pm UTC](https://discuss.elastic.co/t/using-prune-filter-to-remove-null-value-fields/191659/5 "2019-08-19T15:29:28Z")

</div>

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