# HOW TO logstash convert all fields to integer(or some fields)

**URL:** https://discuss.elastic.co/t/how-to-logstash-convert-all-fields-to-integer-or-some-fields/215660
**Category:** Logstash
**Created:** [January 20, 2020, 1:39am UTC](https://discuss.elastic.co/t/how-to-logstash-convert-all-fields-to-integer-or-some-fields/215660 "2020-01-20T01:39:39Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![esongi](https://avatars.discourse-cdn.com/v4/letter/e/96bed5/32.png) [@esongi](https://discuss.elastic.co/u/esongi)
#### Post date: [January 20, 2020, 1:39am UTC](https://discuss.elastic.co/t/how-to-logstash-convert-all-fields-to-integer-or-some-fields/215660/1 "2020-01-20T01:39:39Z")

</div>

Hello I am a foreign developer. Even if the translation is awkward, please understand

My process is Elastic \>\> logstash \>\> fileBeat \>\> Kibana

Logstash reads and uses csv file. The flow creates a csv file containing the headers, and then the data is stacked line by line.

The header of the csv file is "no, item, cherry, apple". All subsequent values ​​are numeric.  
ex) no, item, cherry, apple  
1, 2, 3, 4

The first header is all text. I want to change all header types to integers when reading. "no" and "item" are fixed, but the "cherry" and "apple" are fluid, so they can't fix csv columns What method should I use? Should I use "ruby filter"? I don't know ruby ​​yet

This is my script now. Thank you for letting us know what you need to add or edit.

```auto
input {

  beats {
    host => "localhost"
    port => "5044"
  }

}

filter {

  csv {
    #separator => ","
    #autogenerate_column_names => true
    skip_header => true
    autogenerate_column_names => true
    autodetect_column_names => true
  }

  mutate {
      remove_field => [
          "@version",
          "path",
          "host",
          "tags",
          "offset",
          "agent" 
      ]
      
   #convert => ["[%{field}][long]", "integer"]
  }

  grok { 
    match => { "message" => "%{COMBINEDAPACHELOG}" }
   }

  date {
     #match => ["timestamp", "dd/MMM/yyyy:HH:mm:ss Z"]
     match => ["timestamp", "dd/MMM/yyyy:HH:mm:ss Z"]
     locale => "ko"
   }
}

output {
  elasticsearch {
    hosts => "http://localhost:9200"
    index => "blank"
    manage_template => false
  }
}

```

---

<div class="post-metadata">

### Author: ![scott\_stash](https://avatars.discourse-cdn.com/v4/letter/s/c89c15/32.png) [@scott\_stash](https://discuss.elastic.co/u/scott_stash)
#### Post date: [January 20, 2020, 5:36am UTC](https://discuss.elastic.co/t/how-to-logstash-convert-all-fields-to-integer-or-some-fields/215660/2 "2020-01-20T05:36:16Z")

</div>

Does the convert function in the csv filter work for you:

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

```
  csv {
    convert => {
      "column1" => "integer"
      "column2" => "boolean"
    }

```

In my case I have a template when I write to ES that sets my datatype based on field name.

---

<div class="post-metadata">

### Author: ![esongi](https://avatars.discourse-cdn.com/v4/letter/e/96bed5/32.png) [@esongi](https://discuss.elastic.co/u/esongi)
#### Post date: [January 20, 2020, 6:09am UTC](https://discuss.elastic.co/t/how-to-logstash-convert-all-fields-to-integer-or-some-fields/215660/3 "2020-01-20T06:09:25Z")

</div>

I knew it. These fields not fixed, dynamic. I want how to convert integer to dynamic all fileds .

---

<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: [February 17, 2020, 6:09am UTC](https://discuss.elastic.co/t/how-to-logstash-convert-all-fields-to-integer-or-some-fields/215660/4 "2020-02-17T06:09:25Z")

</div>

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