# How to read "true/false" values from a csv-file and parse them to bool datatype

**URL:** <https://discuss.elastic.co/t/how-to-read-true-false-values-from-a-csv-file-and-parse-them-to-bool-datatype/132988>\
**Category:** Logstash\
**Created:** [May 23, 2018, 11:56am UTC](https://discuss.elastic.co/t/how-to-read-true-false-values-from-a-csv-file-and-parse-them-to-bool-datatype/132988 "2018-05-23T11:56:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![magida](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magida/32/31503_2.png) [@magida](https://discuss.elastic.co/u/magida)\
**Post date:** [May 23, 2018, 11:56am UTC](https://discuss.elastic.co/t/how-to-read-true-false-values-from-a-csv-file-and-parse-them-to-bool-datatype/132988/1 "2018-05-23T11:56:27Z")

</div>

Hello,

I am currently in the midst of reading a bunch of logfiles in a csv-format using logstash. Now a problem that i've come across which i've tried to solve by myself but failed, is that that when a boolean value is read, E.g. "true", when indexed into elasticsearch it is typed as a string, but what i want is to make it a boolean to be used for aggregation etc.  
The catch is that i can't just use convert or mutate, as i have no idea which columns may contain these "true/false" values. So i guess i have to use something akin to the numeric\_detection to figure out if the value being read is actually a boolean or not, is this even possible?

Hope someone can help me out.

---

<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:** [May 23, 2018, 1:52pm UTC](https://discuss.elastic.co/t/how-to-read-true-false-values-from-a-csv-file-and-parse-them-to-bool-datatype/132988/2 "2018-05-23T13:52:39Z")

</div>

```auto
    csv {}
    ruby {
        code => '
            event.to_hash.each do |k, v|
                if ["true", "false"].include? v.to_s.downcase
                    event.set(k, v.to_s.downcase == "true")
                end
            end
        '
    }

```

---

<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:** [June 20, 2018, 1:52pm UTC](https://discuss.elastic.co/t/how-to-read-true-false-values-from-a-csv-file-and-parse-them-to-bool-datatype/132988/3 "2018-06-20T13:52:41Z")

</div>

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