# Drop fields with key that contain string and value \<1

**URL:** https://discuss.elastic.co/t/drop-fields-with-key-that-contain-string-and-value-1/271672
**Category:** Logstash
**Created:** [April 29, 2021, 3:07pm UTC](https://discuss.elastic.co/t/drop-fields-with-key-that-contain-string-and-value-1/271672 "2021-04-29T15:07:09Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Mike\_Clarke](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mike_clarke/32/87948_2.png) [@Mike\_Clarke](https://discuss.elastic.co/u/Mike_Clarke)
#### Post date: [April 29, 2021, 3:07pm UTC](https://discuss.elastic.co/t/drop-fields-with-key-that-contain-string-and-value-1/271672/1 "2021-04-29T15:07:09Z")

</div>

I have a document that contains multiple fields with name `metrics.time.*`. I would like to be able to drop all fields from the event that have `key => metrics.time*` and `value < 1`. Can this be accomplished? I tried doing something like this which doesn't work

```auto
filter {
  ruby {
    code => "
      event.to_hash.each { |key, value|
        if key =~ metrics.time and value <=1 then
          event.remove(key)
      }
    "
  }
}

```

---

<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: [April 29, 2021, 5:53pm UTC](https://discuss.elastic.co/t/drop-fields-with-key-that-contain-string-and-value-1/271672/2 "2021-04-29T17:53:02Z")

</div>

If you run this configuration the metrics.time.foo field will have been removed from the event

```
input { generator { count => 1 lines => [''] } }
filter {
     mutate { add_field => { "[metrics.time.foo]" => 0.8 } }
     mutate { convert => { "[metrics.time.foo]" => "float" } }
    ruby {
        code => '
            event.to_hash.each { |key, value|
                if key =~ /metrics.time/ and value <= 1 then
                    event.remove(key)
                end
            }
        '
    }
}
output { stdout { codec => rubydebug { metadata => false } } }

```

If that does not work for your events then make sure that value is a float (or .to\_f it in the ruby filter, but note that for things that are not actually floats .to\_f will return zero). Also, do you really have periods in name of the field or do you have [metrics][time][someField]?

---

<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: [May 27, 2021, 5:53pm UTC](https://discuss.elastic.co/t/drop-fields-with-key-that-contain-string-and-value-1/271672/3 "2021-05-27T17:53:24Z")

</div>

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