# How can convert field to int, float

**URL:** <https://discuss.elastic.co/t/how-can-convert-field-to-int-float/49702>\
**Category:** Logstash\
**Created:** [May 10, 2016, 7:49pm UTC](https://discuss.elastic.co/t/how-can-convert-field-to-int-float/49702 "2016-05-10T19:49:00Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmorell](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cmorell/32/9700_2.png) [@cmorell](https://discuss.elastic.co/u/cmorell)\
**Post date:** [May 10, 2016, 7:49pm UTC](https://discuss.elastic.co/t/how-can-convert-field-to-int-float/49702/1 "2016-05-10T19:49:01Z")

</div>

Hello,

I'm starting to use ELK, but I have a problem to convert fields... always, all the fields types are string.

Here an example of log line:

`2016-05-10 19:44:37 123 12 199`

and here logstash config file:

`input { file { type => "platform" path => "/home/vagrant/platform.log" start_position => beginning } } filter { if [type]=="platform" { grok { match => ["message", "%{TIMESTAMP_ISO8601:timestamp} %{NUMBER:id:int} %{NUMBER:platform_type:int} %{NUMBER:value:int}"] } mutate { convert => { "value" => "integer" "platform_type" => "integer" "id" => "integer" } } } } output { elasticsearch { hosts => ["localhost:9200"] index => "platform-%{+YYYY-MM-dd}" } }`

and when I test it, using

`curl -XGET 'http://localhost:9200/platfrom-*'`

return

`{"platfrom-2016-05-10":{"aliases":{},"mappings":{"platfrom":{"properties":{"@timestamp":{"type":"date","format":"strict_date_optional_time||epoch_millis"},"@version":{"type":"string"},"host":{"type":"string"},"id":{"type":"string"},"message":{"type":"string"},"path":{"type":"string"},"platfrom_type":{"type":"string"},"timestamp":{"type":"string"},"type":{"type":"string"},"value":{"type":"string"}}}},"settings":{"index":{"creation_date":"1462902506058","number_of_shards":"5","number_of_replicas":"1","uuid":"qs60O-FRSzO5rGv2E0nEzQ","version":{"created":"2030299"}}},"warmers":{}}}`

All fields are strings...

I don't know what I am doing bad, can anyone help me?

Thanks

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [May 11, 2016, 6:06am UTC](https://discuss.elastic.co/t/how-can-convert-field-to-int-float/49702/2 "2016-05-11T06:06:09Z")

</div>

Ideally, you should be setting this in ES as well via a mapping or a template.

---

<div class="post-metadata">

**Author:** ![fbaligand](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fbaligand/32/5657_2.png) [@fbaligand](https://discuss.elastic.co/u/fbaligand)\
**Post date:** [May 11, 2016, 7:51am UTC](https://discuss.elastic.co/t/how-can-convert-field-to-int-float/49702/3 "2016-05-11T07:51:30Z")

</div>

To me, your logstash configuration is nice.  
And normally, you have not to add "mutate" filter, since in grok filter, you already convert fields to int using `:int`.

To be sure that your conversion is correct, you can add this output :

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

```

If it is correct, you see `id => 1`  
If it is not correct, you see `id => "1"`

That said, you have to know that elasticsearch index defines its mapping using first document.  
So I invite you to :

- drop index, put a document using logstash, and verify that new index has good mapping
- check that there is nothing elsewhere (in your logstash pipeline or elsewhere) that create documents with int fields as a string.

---

<div class="post-metadata">

**Author:** ![krish](https://avatars.discourse-cdn.com/v4/letter/k/c57346/32.png) [@krish](https://discuss.elastic.co/u/krish)\
**Post date:** [February 17, 2017, 8:09am UTC](https://discuss.elastic.co/t/how-can-convert-field-to-int-float/49702/4 "2017-02-17T08:09:24Z")

</div>

its not working for me too i used both types of config (i.e) {number:num:int} and mutate any suggestions or ideas .pls..

---

<div class="post-metadata">

**Author:** ![fbaligand](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fbaligand/32/5657_2.png) [@fbaligand](https://discuss.elastic.co/u/fbaligand)\
**Post date:** [February 17, 2017, 8:30am UTC](https://discuss.elastic.co/t/how-can-convert-field-to-int-float/49702/5 "2017-02-17T08:30:44Z")

</div>

Did you try the following output configuration to check that Logstash does the conversion right ?  
Because maybe your problem is not Logstash conversion but elasticsearch mapping.

> [@fbaligand](#):
>
> stdout { codec =\> rubydebug }

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [February 17, 2017, 8:57am UTC](https://discuss.elastic.co/t/how-can-convert-field-to-int-float/49702/6 "2017-02-17T08:57:29Z")

</div>

Please start your own thread, this one is super old.

---

<div class="post-metadata">

**Author:** ![krish](https://avatars.discourse-cdn.com/v4/letter/k/c57346/32.png) [@krish](https://discuss.elastic.co/u/krish)\
**Post date:** [February 17, 2017, 9:45am UTC](https://discuss.elastic.co/t/how-can-convert-field-to-int-float/49702/7 "2017-02-17T09:45:43Z")

</div>

how to do that? im new to it can you help me??

---

<div class="post-metadata">

**Author:** ![fbaligand](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fbaligand/32/5657_2.png) [@fbaligand](https://discuss.elastic.co/u/fbaligand)\
**Post date:** [February 17, 2017, 7:37pm UTC](https://discuss.elastic.co/t/how-can-convert-field-to-int-float/49702/8 "2017-02-17T19:37:31Z")

</div>

- Go here : [https://discuss.elastic.co/c/logstash](https://discuss.elastic.co/c/logstash)
- Click "New Topic" button

---

<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 6, 2017, 4:28am UTC](https://discuss.elastic.co/t/how-can-convert-field-to-int-float/49702/9 "2017-07-06T04:28:30Z")

</div>


