# Remove\_field with regex as argument

**URL:** https://discuss.elastic.co/t/remove-field-with-regex-as-argument/134001
**Category:** Logstash
**Created:** [May 31, 2018, 8:37am UTC](https://discuss.elastic.co/t/remove-field-with-regex-as-argument/134001 "2018-05-31T08:37:43Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![dr01](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dr01/32/8482_2.png) [@dr01](https://discuss.elastic.co/u/dr01)
#### Post date: [May 31, 2018, 8:37am UTC](https://discuss.elastic.co/t/remove-field-with-regex-as-argument/134001/1 "2018-05-31T08:37:43Z")

</div>

I'd like to remove all fields that begin by "foobar". Is there any way to pass a regex to the `remove_field` command, or is there any remove command that accepts regexs?

---

<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 31, 2018, 9:39am UTC](https://discuss.elastic.co/t/remove-field-with-regex-as-argument/134001/2 "2018-05-31T09:39:42Z")

</div>

Use a prune filter.

---

<div class="post-metadata">

### Author: ![dr01](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dr01/32/8482_2.png) [@dr01](https://discuss.elastic.co/u/dr01)
#### Post date: [May 31, 2018, 2:38pm UTC](https://discuss.elastic.co/t/remove-field-with-regex-as-argument/134001/3 "2018-05-31T14:38:49Z")

</div>

Unfortunately the field is a subfield (obtained parsing a JSON), and the `prune` filter doesn't support that.

I thought about using the `mutate` filter to rename the subfield as a root field, but the rename command doesn't allow regexs, so I'm back to square one. Any other ideas?

---

<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 31, 2018, 2:58pm UTC](https://discuss.elastic.co/t/remove-field-with-regex-as-argument/134001/4 "2018-05-31T14:58:33Z")

</div>

Then you'll have to use a ruby filter. I'm pretty sure examples have been posted in the past.

---

<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 28, 2018, 3:04pm UTC](https://discuss.elastic.co/t/remove-field-with-regex-as-argument/134001/6 "2018-06-28T15:04:13Z")

</div>

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