# Replace multiple value in a specified field

**URL:** https://discuss.elastic.co/t/replace-multiple-value-in-a-specified-field/134780
**Category:** Logstash
**Created:** [June 6, 2018, 10:23am UTC](https://discuss.elastic.co/t/replace-multiple-value-in-a-specified-field/134780 "2018-06-06T10:23:42Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![f26227279](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/f26227279/32/21296_2.png) [@f26227279](https://discuss.elastic.co/u/f26227279)
#### Post date: [June 6, 2018, 10:23am UTC](https://discuss.elastic.co/t/replace-multiple-value-in-a-specified-field/134780/1 "2018-06-06T10:23:42Z")

</div>

Hi, I want to replace 6 to TCP and 17 to UDP in the PROTOCOL field.  
this is my logstash config:

```
input{
        tcp{
                host => "163.19.X.X"
                port => 5510
                codec => json

        }
}
filter{
        if [PROTOCOL] == "6"{
             mutate{replace => {"PROTOCOL"=>"TCP"}}
          }
        if [PROTOCOL] == "17"{
             mutate{replace => {"PROTOCOL"=>"UDP"}}
          }
}
output{
elasticsearch {
                codec => "json"
                hosts => ["163.19.X.X:9200","163.19.X.X:9200","163.19.X.X:9200"]
                user => "elastic"
                password => "9ol./;p0"

        }

```

![image](https://us1.discourse-cdn.com/elastic/original/3X/b/5/b5e1b4f594244bef3be258987982e3672520a9de.png)

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/b/2bf077b4751867903a479571fc9bb8b8e6fd9695.png)  
but it can't work.  
plz help me ☹

---

<div class="post-metadata">

### Author: ![arkady\_renko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/arkady_renko/32/30160_2.png) [@arkady\_renko](https://discuss.elastic.co/u/arkady_renko)
#### Post date: [June 7, 2018, 3:39pm UTC](https://discuss.elastic.co/t/replace-multiple-value-in-a-specified-field/134780/2 "2018-06-07T15:39:47Z")

</div>

is PROTOCOL string or integer?

sample input would be helpful to debug.

---

<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: [June 7, 2018, 4:17pm UTC](https://discuss.elastic.co/t/replace-multiple-value-in-a-specified-field/134780/3 "2018-06-07T16:17:20Z")

</div>

Or change the output to be 'stdout { codec =\> rubydebug }'. We can see that PROTOCOL is a string in Kibana, but that does not require that it is one in logstash. If rubydebug shows

```
PROTOCOL => 5

```

rather than

```
PROTOCOL => "5"

```

then you should change the if condition to match it

---

<div class="post-metadata">

### Author: ![f26227279](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/f26227279/32/21296_2.png) [@f26227279](https://discuss.elastic.co/u/f26227279)
#### Post date: [June 12, 2018, 1:13am UTC](https://discuss.elastic.co/t/replace-multiple-value-in-a-specified-field/134780/4 "2018-06-12T01:13:35Z")

</div>

thanks for your reply !  
I found the "PROTOCOL" default type is number, and I want to change it to string such as 6 to TCP.  
How can I do?

this is the logstash debug log:

`[2018-06-12T09:09:09,431][WARN][logstash.outputs.elasticsearch] Could not index event to Elasticsearch. {:status=>400, :action=>["index", {:_id=>nil, :_index=>"logstash-2018.06.12", :_type=>"doc", :_routing=>nil}, #<LogStash::Event:0x583a02c8>], :response=>{"index"=>{"_index"=>"logstash-2018.06.12", "_type"=>"doc", "_id"=>"CI2H8WMBuct0wI0D_4PU", "status"=>400, "error"=>{"type"=>"mapper_parsing_exception", "reason"=>"failed to parse [PROTOCOL]", "caused_by"=>{"type"=>"illegal_argument_exception", "reason"=>"For input string: \"TCP\""}}}}}`

---

<div class="post-metadata">

### Author: ![f26227279](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/f26227279/32/21296_2.png) [@f26227279](https://discuss.elastic.co/u/f26227279)
#### Post date: [June 12, 2018, 2:55am UTC](https://discuss.elastic.co/t/replace-multiple-value-in-a-specified-field/134780/5 "2018-06-12T02:55:42Z")

</div>

it can work now!  
final config:

```
input{
        tcp{
                host => "163.19.XX.X"
                port => 5510
                codec => json

        }
}
filter{
        if [PROTOCOL]==6 {
             mutate{replace => {"PROTOCOL"=>"TCP"}}
          }
        if [PROTOCOL]==17 {
             mutate{replace => {"PROTOCOL"=>"UDP"}}
          }
        if [PROTOCOL]==1 {
             mutate{replace => {"PROTOCOL"=>"ICMP"}}
          }

}
output{
elasticsearch {
                codec => "json"
                hosts => ["163.19.X.XX:9200"]
        #user => "elastic"
        #password => "9ol./;p0"

        }

                stdout{codec=> rubydebug}

}
```

---

<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: [June 12, 2018, 6:59am UTC](https://discuss.elastic.co/t/replace-multiple-value-in-a-specified-field/134780/6 "2018-06-12T06:59:25Z")

</div>

FYI a [translate](https://www.elastic.co/guide/en/logstash/current/plugins-filters-translate.html) filter would be another way of doing this. For 3 values I don't think it matters which one you use.

---

<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 10, 2018, 6:59am UTC](https://discuss.elastic.co/t/replace-multiple-value-in-a-specified-field/134780/7 "2018-07-10T06:59:41Z")

</div>

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