# Logstash csv check fields for numeric and mutate to integer

**URL:** <https://discuss.elastic.co/t/logstash-csv-check-fields-for-numeric-and-mutate-to-integer/45293>\
**Category:** Logstash\
**Created:** [March 24, 2016, 12:42am UTC](https://discuss.elastic.co/t/logstash-csv-check-fields-for-numeric-and-mutate-to-integer/45293 "2016-03-24T00:42:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rbkumar88](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@rbkumar88](https://discuss.elastic.co/u/rbkumar88)\
**Post date:** [March 24, 2016, 12:42am UTC](https://discuss.elastic.co/t/logstash-csv-check-fields-for-numeric-and-mutate-to-integer/45293/1 "2016-03-24T00:42:10Z")

</div>

Hi,

I have a csv filter which generates the fields. I want to check all the generated fields (whether all the characters are numbers), if then mutate those fields to Integer.

Regards  
Bharath

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [March 24, 2016, 4:43am UTC](https://discuss.elastic.co/t/logstash-csv-check-fields-for-numeric-and-mutate-to-integer/45293/2 "2016-03-24T04:43:48Z")

</div>

And the [`convert` option](https://www.elastic.co/guide/en/logstash/current/plugins-filters-csv.html#plugins-filters-csv-convert) that allows type conversion of pre-configured fields won't cut it?

---

<div class="post-metadata">

**Author:** ![rbkumar88](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@rbkumar88](https://discuss.elastic.co/u/rbkumar88)\
**Post date:** [March 24, 2016, 3:04pm UTC](https://discuss.elastic.co/t/logstash-csv-check-fields-for-numeric-and-mutate-to-integer/45293/3 "2016-03-24T15:04:53Z")

</div>

Hi Magnus  
Thanks for the reply. But I am aware of the convert option in CSV filter. But my question is more of auto-identifying the eligible fields for conversion to integer. Say I have a CSV with nearly 100 fields with a mix of string and number fields. Is there any generic conditional(like the following) in logstash to run through all those fields and identify number fields.

if [field] =~ /_.^/\d$_./{  
CSV(or mutate)  
{  
Convert =\> { [field] =\> "integer" }  
}  
}  
Hope you got my question this time

Thanks  
Bharath

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [March 24, 2016, 7:03pm UTC](https://discuss.elastic.co/t/logstash-csv-check-fields-for-numeric-and-mutate-to-integer/45293/4 "2016-03-24T19:03:11Z")

</div>

Currently you need to write a small piece of Ruby in a ruby filter to accomplish this, but it's reasonable for the csv filter to guess the data type of the columns. I created a GitHub issue for this feature request.

> <https://github.com/logstash-plugins/logstash-filter-csv/issues/27>

---

<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, 5:05am UTC](https://discuss.elastic.co/t/logstash-csv-check-fields-for-numeric-and-mutate-to-integer/45293/5 "2017-07-06T05:05:27Z")

</div>


