# Autodetect\_column\_names is not working as expected in csv filter plugin

**URL:** <https://discuss.elastic.co/t/autodetect-column-names-is-not-working-as-expected-in-csv-filter-plugin/333269>\
**Category:** Logstash\
**Created:** [May 12, 2023, 8:43am UTC](https://discuss.elastic.co/t/autodetect-column-names-is-not-working-as-expected-in-csv-filter-plugin/333269 "2023-05-12T08:43:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vladislav](https://avatars.discourse-cdn.com/v4/letter/v/bbce88/32.png) [@vladislav](https://discuss.elastic.co/u/vladislav)\
**Post date:** [May 12, 2023, 8:43am UTC](https://discuss.elastic.co/t/autodetect-column-names-is-not-working-as-expected-in-csv-filter-plugin/333269/1 "2023-05-12T08:43:38Z")

</div>

Hi,

I have this logstash .conf file:

```auto
input {
  file {
    path => "/eee/*.csv"
    start_position => "beginning"
    sincedb_path => "/dev/null"
  }
}
filter {
  csv {
   autodetect_column_names => true
 }
}

```

And multiple .csv files, containing different data, all of them need to be placed in the same index.  
Example, file1.csv contains:

Name,City,Date,Comment  
Josh,city1,2022-01-02,active  
John,city2,2022-04-29,passive

And file2.csv contains different headers:  
Name,first\_seen,last\_seen,favorite  
Josh,2020-04-05,2022-01-02,yes  
John,2019-05-05,2022-04-29,no

And when I open index in Kibana, after indexing in elasticsearch I see that all the header names were taken from the first file  
So, from file2.csv I see:  
Name: Josh, City: 2020-04-05, Date: 2022-01-02, Comment: yes

How can I avoid this problem? Big thanks in advance. Using logstash 8.7.1, pipeline.workers is set to 1.

---

<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 12, 2023, 3:53pm UTC](https://discuss.elastic.co/t/autodetect-column-names-is-not-working-as-expected-in-csv-filter-plugin/333269/2 "2023-05-12T15:53:35Z")

</div>

autodetect\_column\_names sets the names once and never changes them. If you want multiple sets of column names then you need multiple csv filters.

You may be able to use a conditional based on the [number of fields](https://discuss.elastic.co/t/using-ruby-to-count-the-number-of-fields-in-a-message-then-apply-csv-depending-on-the-count/177880/2), or else based on the [log][file][path].

---

<div class="post-metadata">

**Author:** ![vladislav](https://avatars.discourse-cdn.com/v4/letter/v/bbce88/32.png) [@vladislav](https://discuss.elastic.co/u/vladislav)\
**Post date:** [May 15, 2023, 6:39am UTC](https://discuss.elastic.co/t/autodetect-column-names-is-not-working-as-expected-in-csv-filter-plugin/333269/3 "2023-05-15T06:39:13Z")

</div>

thanks!

---

<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 12, 2023, 6:39am UTC](https://discuss.elastic.co/t/autodetect-column-names-is-not-working-as-expected-in-csv-filter-plugin/333269/4 "2023-06-12T06:39:55Z")

</div>

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