# Logstash to convert all numeric field to float

**URL:** <https://discuss.elastic.co/t/logstash-to-convert-all-numeric-field-to-float/206100>\
**Category:** Logstash\
**Created:** [October 31, 2019, 8:20pm UTC](https://discuss.elastic.co/t/logstash-to-convert-all-numeric-field-to-float/206100 "2019-10-31T20:20:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jalu](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jalu](https://discuss.elastic.co/u/jalu)\
**Post date:** [October 31, 2019, 8:20pm UTC](https://discuss.elastic.co/t/logstash-to-convert-all-numeric-field-to-float/206100/1 "2019-10-31T20:20:46Z")

</div>

Hi, I recently start to work on a JSON\> logstash \> influx pipeline , I wonder if there is a way to make logstash to read every numeric value from JSON into float and write them into Influx. For now, some of the fields are Integer and others are Float.

Thank you

---

<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:** [October 31, 2019, 9:39pm UTC](https://discuss.elastic.co/t/logstash-to-convert-all-numeric-field-to-float/206100/2 "2019-10-31T21:39:06Z")

</div>

You can convert every top level integer to a float using

```
    ruby {
        code => '
            event.to_hash.each { |k, v|
                if v.is_a? Integer
                    event.set(k, v.to_f)
                end
            }
        '
    }

```

That will not be limited that were parsed from the JSON.

---

<div class="post-metadata">

**Author:** ![jalu](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jalu](https://discuss.elastic.co/u/jalu)\
**Post date:** [November 1, 2019, 4:21pm UTC](https://discuss.elastic.co/t/logstash-to-convert-all-numeric-field-to-float/206100/3 "2019-11-01T16:21:04Z")

</div>

Works like a charm, side note that this goes into filter{}

---

<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:** [November 29, 2019, 4:21pm UTC](https://discuss.elastic.co/t/logstash-to-convert-all-numeric-field-to-float/206100/4 "2019-11-29T16:21:12Z")

</div>

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