# Logstash - how to remove strings within a field (whose content itself a raw string)?

**URL:** <https://discuss.elastic.co/t/logstash-how-to-remove-strings-within-a-field-whose-content-itself-a-raw-string/286561>\
**Category:** Logstash\
**Created:** [October 13, 2021, 2:18am UTC](https://discuss.elastic.co/t/logstash-how-to-remove-strings-within-a-field-whose-content-itself-a-raw-string/286561 "2021-10-13T02:18:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![helloworld1234](https://avatars.discourse-cdn.com/v4/letter/h/7feea3/32.png) [@helloworld1234](https://discuss.elastic.co/u/helloworld1234)\
**Post date:** [October 13, 2021, 2:18am UTC](https://discuss.elastic.co/t/logstash-how-to-remove-strings-within-a-field-whose-content-itself-a-raw-string/286561/1 "2021-10-13T02:18:03Z")

</div>

I have a event that consists of various fields, one of which is called "raw\_message". This field's contents is a raw string eg.

Input:

```auto
raw_message: "Raw user details:: [location:london name:kris wu id:L3j5k category:vip]"

```

Output:

```auto
raw_message: "Raw user details:: [location:london category:vip]"

```

I would like to remove name and id from this field. I understand remove\_field doesnt work for the mutate or filter plugin since that function removes the entire field which is not what I'm looking for.

---

<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:** [October 13, 2021, 2:44am UTC](https://discuss.elastic.co/t/logstash-how-to-remove-strings-within-a-field-whose-content-itself-a-raw-string/286561/2 "2021-10-13T02:44:25Z")

</div>

You may be able to do it using mutate+gsub.

---

<div class="post-metadata">

**Author:** ![helloworld1234](https://avatars.discourse-cdn.com/v4/letter/h/7feea3/32.png) [@helloworld1234](https://discuss.elastic.co/u/helloworld1234)\
**Post date:** [October 13, 2021, 4:53am UTC](https://discuss.elastic.co/t/logstash-how-to-remove-strings-within-a-field-whose-content-itself-a-raw-string/286561/3 "2021-10-13T04:53:22Z")

</div>

Thanks for the reply. Correct me if i misunderstood gsub, but wouldnt it only replace the highlighted field?

i.e.

```auto
 filter {
      mutate {
        gsub => [
          # replace all forward slashes with underscore
          "raw_message", "name", " ****",
        ]
      }
    }

```

input:

```auto
raw_message: "Raw user details:: [location:london name:kris wu id:L3j5k category:vip]"

```

output:

```auto
raw_message: "Raw user details:: [location:london **** :kris wu id:L3j5k category:vip]"

```

---

<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:** [October 13, 2021, 4:22pm UTC](https://discuss.elastic.co/t/logstash-how-to-remove-strings-within-a-field-whose-content-itself-a-raw-string/286561/4 "2021-10-13T16:22:58Z")

</div>

You could try something like

```
mutate { gsub => ["raw_message", "name:\w+ ", ""] }
```

---

<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:** [November 10, 2021, 4:23pm UTC](https://discuss.elastic.co/t/logstash-how-to-remove-strings-within-a-field-whose-content-itself-a-raw-string/286561/5 "2021-11-10T16:23:17Z")

</div>

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