# Change a string in a field for a number

**URL:** <https://discuss.elastic.co/t/change-a-string-in-a-field-for-a-number/208735>\
**Category:** Logstash\
**Created:** [November 20, 2019, 3:52pm UTC](https://discuss.elastic.co/t/change-a-string-in-a-field-for-a-number/208735 "2019-11-20T15:52:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Incauto](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/incauto/32/60149_2.png) [@Incauto](https://discuss.elastic.co/u/Incauto)\
**Post date:** [November 20, 2019, 3:52pm UTC](https://discuss.elastic.co/t/change-a-string-in-a-field-for-a-number/208735/1 "2019-11-20T15:52:36Z")

</div>

Hi, from time to time In the milliseconds field( that is for numbers ) appears the string: "disabled", what Im trying to do, is that every time the string "disabled" appears, change for it the number "0" I have tried with gsub without results....do I need a conditional? how can I do this?

```
filter {
        grok {
                match => {"message" => "%{DATA:server}\s%{DATA:milliseconds}"}
        }

        mutate {
            gsub => [
                     "milliseconds" , "disabled", "0"
              ]
            convert => {
                    "milliseconds" => "integer"
                }
        }
```

---

<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:** [November 20, 2019, 6:01pm UTC](https://discuss.elastic.co/t/change-a-string-in-a-field-for-a-number/208735/2 "2019-11-20T18:01:13Z")

</div>

What does the resulting event look like if you use

```
output { stdout { codec => rubydebug } }

```

Note that mutate does processing in a [fixed order](https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html#plugins-filters-mutate-proc_order) and convert comes before gsub, so you need to split that into two mutate filters.

---

<div class="post-metadata">

**Author:** ![Incauto](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/incauto/32/60149_2.png) [@Incauto](https://discuss.elastic.co/u/Incauto)\
**Post date:** [November 20, 2019, 6:16pm UTC](https://discuss.elastic.co/t/change-a-string-in-a-field-for-a-number/208735/3 "2019-11-20T18:16:42Z")

</div>

It shows all the fields but not milliseconds, testing in grok debbuger, seems that DATA doesnt accept numbers, so the field doesnt even appears in the stdout, later I try this also without success

```
filter {
    grok {
            match => {"message" => "%{DATA:server}\s%{NUMBER:milisegundos}"}
    }

    if [milisegundos] == "disabled" {
            mutate {
                    replace => ["milisegundos", 0]
            }
    }

    mutate {

            add_field => {
                    "origen" => "alpha"
                    "horayfecha" => "%{hora} %{fecha}"
            }
            convert => {
                    "milisegundos" => "integer"
            }
    }

```

that trows a grok parse failure whenever it find the string "disabled"

---

<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:** [December 18, 2019, 6:16pm UTC](https://discuss.elastic.co/t/change-a-string-in-a-field-for-a-number/208735/4 "2019-12-18T18:16:49Z")

</div>

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