# Removing field reference in field as string value

**URL:** <https://discuss.elastic.co/t/removing-field-reference-in-field-as-string-value/163099>\
**Category:** Logstash\
**Created:** [January 6, 2019, 11:00pm UTC](https://discuss.elastic.co/t/removing-field-reference-in-field-as-string-value/163099 "2019-01-06T23:00:14Z")\
**Posts on this page:** 3\
**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:** [January 6, 2019, 11:00pm UTC](https://discuss.elastic.co/t/removing-field-reference-in-field-as-string-value/163099/1 "2019-01-06T23:00:14Z")

</div>

I am adding a field that references another field, `add_field => { "newfield" => "%{oldfield}"}`.

Sometimes the referenced field is empty, resulting in newfield containing a string with the value %{oldfield}. How can I remove this string?

I've tried using mutate's gsub with pattern's `"%{oldfield}"`, `"%\{oldfield\}"`, and `"\%\{oldfield\}"`  
I've also tried using IF with a regex expression and expressing it in string form but neither of them seems to work. Any ideas?

---

<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:** [January 7, 2019, 9:17pm UTC](https://discuss.elastic.co/t/removing-field-reference-in-field-as-string-value/163099/2 "2019-01-07T21:17:19Z")

</div>

If the referenced field is empty I would expect add\_field to add an empty field. I would only expect a field containing "%{oldfield}" if oldfield is missing on the event.

Can you use this?...

```
filter { if [newfield] == "%{oldfield}" { mutate { remove_field => "newfield" } } }
```

---

<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:** [February 4, 2019, 9:17pm UTC](https://discuss.elastic.co/t/removing-field-reference-in-field-as-string-value/163099/3 "2019-02-04T21:17:40Z")

</div>

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