# Using replace in Logstash

**URL:** https://discuss.elastic.co/t/using-replace-in-logstash/216227
**Category:** Logstash
**Created:** [January 23, 2020, 11:31am UTC](https://discuss.elastic.co/t/using-replace-in-logstash/216227 "2020-01-23T11:31:51Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![saravana\_hariharan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/saravana_hariharan/32/57379_2.png) [@saravana\_hariharan](https://discuss.elastic.co/u/saravana_hariharan)
#### Post date: [January 23, 2020, 11:31am UTC](https://discuss.elastic.co/t/using-replace-in-logstash/216227/1 "2020-01-23T11:31:51Z")

</div>

if [score] \>= "35"

mutate  
replace =\> ["score","Success"]

my error is if score Greater than equal to 35 value considered as success so im displaying graph in success, but it only shows 35 to 99 values in label name of success and above 99 three digit values cant be changed to label of success name  
it shows like this  
123  
101  
156  
actual output is instead of values consider as success

---

<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 23, 2020, 1:55pm UTC](https://discuss.elastic.co/t/using-replace-in-logstash/216227/2 "2020-01-23T13:55:49Z")

</div>

Is [score] a string in logstash? If it is an integer then that should be

```
if [score] >= 35

```

without the quotes. I think \>= will do unexpected things if it is a string.

---

<div class="post-metadata">

### Author: ![saravana\_hariharan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/saravana_hariharan/32/57379_2.png) [@saravana\_hariharan](https://discuss.elastic.co/u/saravana_hariharan)
#### Post date: [January 23, 2020, 2:19pm UTC](https://discuss.elastic.co/t/using-replace-in-logstash/216227/3 "2020-01-23T14:19:09Z")

</div>

Without quotation file cant be readed and i get output from below code but the label cant be matched to all values it match only two digit values

if [score] \>= "35"  
mutate  
replace =\> ["score","Success"]

my data is  
score  
36  
45  
100  
120  
but it can taken only two digit values to replaced success and three digit values directly printed like this  
100  
120

help me

---

<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 23, 2020, 6:03pm UTC](https://discuss.elastic.co/t/using-replace-in-logstash/216227/4 "2020-01-23T18:03:30Z")

</div>

It is not doing a numeric compare. Consider

```
input { generator { count => 1 lines => ['36', '45', '100', '120', '349', '351'] } }
filter {
    if [message] >= "35" {
        mutate { add_field => { "branch" => true } }
    } else {
        mutate { add_field => { "branch" => false } }
    }
}
output { stdout { codec => rubydebug { metadata => false } } }

```

That results in

```auto
{
    "@timestamp" => 2020-01-23T17:57:37.288Z,
        "branch" => "true",
       "message" => "36"
}
{
    "@timestamp" => 2020-01-23T17:57:37.296Z,
        "branch" => "true",
       "message" => "45"
}
{
    "@timestamp" => 2020-01-23T17:57:37.297Z,
        "branch" => "true",
       "message" => "351"
}
{
    "@timestamp" => 2020-01-23T17:57:37.296Z,
        "branch" => "false",
       "message" => "100"
}
{
    "@timestamp" => 2020-01-23T17:57:37.297Z,
        "branch" => "false",
       "message" => "120"
}
{
    "@timestamp" => 2020-01-23T17:57:37.297Z,
        "branch" => "false",
       "message" => "349"
}

```

If however we change that if to be

```
    mutate { convert => { "message" => integer } }
    if [message] >= 35 {

```

then they all go through the "true" branch.

If you put these 6 numbers into a text file and sort it using "sort" it you will get

```auto
100
28
349
35
351
36

```

that reflects the order that your if is evaluating. Obviously "sort -n" returns a different order.

---

<div class="post-metadata">

### Author: ![saravana\_hariharan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/saravana_hariharan/32/57379_2.png) [@saravana\_hariharan](https://discuss.elastic.co/u/saravana_hariharan)
#### Post date: [January 24, 2020, 12:09pm UTC](https://discuss.elastic.co/t/using-replace-in-logstash/216227/5 "2020-01-24T12:09:08Z")

</div>

Hi Badger,  
im using above code but it cant be read the file  
and the error msg following like this

Error parsing json {:source =\>"message" ,:raw =\>"1576978110000 /t 78 /t 35 /r" was Expecting (true,false or null)

---

<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 21, 2020, 12:09pm UTC](https://discuss.elastic.co/t/using-replace-in-logstash/216227/6 "2020-02-21T12:09:09Z")

</div>

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