# Gsub - Basic example

**URL:** https://discuss.elastic.co/t/gsub-basic-example/239436
**Category:** Logstash
**Created:** [July 1, 2020, 8:25am UTC](https://discuss.elastic.co/t/gsub-basic-example/239436 "2020-07-01T08:25:24Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Florent\_Fauvin](https://avatars.discourse-cdn.com/v4/letter/f/d2c977/32.png) [@Florent\_Fauvin](https://discuss.elastic.co/u/Florent_Fauvin)
#### Post date: [July 1, 2020, 8:25am UTC](https://discuss.elastic.co/t/gsub-basic-example/239436/1 "2020-07-01T08:25:24Z")

</div>

Hello,  
I'm trying to use gsub with a very simple example and it doesn't work.

I just want to replace "ef" with "AA" with this example:

```
  mutate {
    add_field => { "field1" => "abc def ghi jkl" }
    gsub => ["field1", "ef","AA"]
  }

```

Could you tell me what is not working please?

Thank you very much,

Florent

---

<div class="post-metadata">

### Author: ![Jenni](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jenni/32/29684_2.png) [@Jenni](https://discuss.elastic.co/u/Jenni)
#### Post date: [July 1, 2020, 8:59am UTC](https://discuss.elastic.co/t/gsub-basic-example/239436/2 "2020-07-01T08:59:10Z")

</div>

`gsub` is an option of the mutate filter. `add_field` is a common option for every kind of filter that is executed if the filter has been successfull. Therefore it is executed after `gsub`. Your field doesn't yet exist when `gsub` is executed. So you'll have to split that up into two mutate filters.

[https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html#plugins-filters-mutate-proc\_order](https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html#plugins-filters-mutate-proc_order)  
[https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html#plugins-filters-mutate-add\_field](https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html#plugins-filters-mutate-add_field)

---

<div class="post-metadata">

### Author: ![Florent\_Fauvin](https://avatars.discourse-cdn.com/v4/letter/f/d2c977/32.png) [@Florent\_Fauvin](https://discuss.elastic.co/u/Florent_Fauvin)
#### Post date: [July 1, 2020, 9:00am UTC](https://discuss.elastic.co/t/gsub-basic-example/239436/3 "2020-07-01T09:00:11Z")

</div>

Thank you, it works!

---

<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: [July 29, 2020, 9:00am UTC](https://discuss.elastic.co/t/gsub-basic-example/239436/4 "2020-07-29T09:00:14Z")

</div>

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