# Logstash convert string to integer

**URL:** https://discuss.elastic.co/t/logstash-convert-string-to-integer/96325
**Category:** Logstash
**Created:** [August 8, 2017, 6:56pm UTC](https://discuss.elastic.co/t/logstash-convert-string-to-integer/96325 "2017-08-08T18:56:00Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![bitesize](https://avatars.discourse-cdn.com/v4/letter/b/ecccb3/32.png) [@bitesize](https://discuss.elastic.co/u/bitesize)
#### Post date: [August 8, 2017, 6:56pm UTC](https://discuss.elastic.co/t/logstash-convert-string-to-integer/96325/1 "2017-08-08T18:56:00Z")

</div>

I have json string array that I am decomposing into separate fields, such as:  
'{"eventid":1,"content":["a","b","c","d"]}'  
after adding some field names and remove\_field content. I get the following:  
{  
"@timestamp" =\> 2017-08-08T13:16:02.523Z,  
"@version" =\> "1",  
"eventid" =\> 1,  
"one0" =\> "a",  
"one1" =\> "b",  
"one2" =\> "c",  
"one3" =\> "d"  
}

I removed all my indices. Started fresh and I tried to convert one1 from string to integer value in the same mutate filter that I added fields and remove\_field above, except that the field still shows as string in Kibana. Not sure why it does not set the type to integer.

---

<div class="post-metadata">

### Author: ![truekonrads](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/truekonrads/32/28104_2.png) [@truekonrads](https://discuss.elastic.co/u/truekonrads)
#### Post date: [August 8, 2017, 7:19pm UTC](https://discuss.elastic.co/t/logstash-convert-string-to-integer/96325/2 "2017-08-08T19:19:37Z")

</div>

[Use mutate convert](https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html#plugins-filters-mutate-convert):

```
filter {
  mutate {
    convert => { "fieldname" => "integer" }
  }
}
```

---

<div class="post-metadata">

### Author: ![bitesize](https://avatars.discourse-cdn.com/v4/letter/b/ecccb3/32.png) [@bitesize](https://discuss.elastic.co/u/bitesize)
#### Post date: [August 8, 2017, 7:49pm UTC](https://discuss.elastic.co/t/logstash-convert-string-to-integer/96325/3 "2017-08-08T19:49:07Z")

</div>

Yes, I did and still not working.

```
filter {
if [event] == 1 {
        mutate {
            add_field => {
                "one1" => "%{[content][0]}"
                "one2" => "%{[content][1]}"
                "one3" => "%{[content][2]}"
                "one4" => "%{[content][3]}"
            }
            convert => { "one1" => "integer" }
            remove_field => ["content", "host"]
        }
    }
}
```

---

<div class="post-metadata">

### Author: ![bitesize](https://avatars.discourse-cdn.com/v4/letter/b/ecccb3/32.png) [@bitesize](https://discuss.elastic.co/u/bitesize)
#### Post date: [August 8, 2017, 8:29pm UTC](https://discuss.elastic.co/t/logstash-convert-string-to-integer/96325/4 "2017-08-08T20:29:01Z")

</div>

Got it. I had to place a new mutate { convert ... } after the existing mutate.

---

<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: [September 5, 2017, 8:29pm UTC](https://discuss.elastic.co/t/logstash-convert-string-to-integer/96325/5 "2017-09-05T20:29:03Z")

</div>

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