# Header in csv while exporting

**URL:** <https://discuss.elastic.co/t/header-in-csv-while-exporting/262958>\
**Category:** Elasticsearch\
**Created:** [February 2, 2021, 10:25am UTC](https://discuss.elastic.co/t/header-in-csv-while-exporting/262958 "2021-02-02T10:25:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ritusingh](https://avatars.discourse-cdn.com/v4/letter/r/ac91a4/32.png) [@ritusingh](https://discuss.elastic.co/u/ritusingh)\
**Post date:** [February 2, 2021, 10:25am UTC](https://discuss.elastic.co/t/header-in-csv-while-exporting/262958/1 "2021-02-02T10:25:02Z")

</div>

Hi,  
I want to know that is there any way through which we can add header in csv file while exporting from elasticsearch via logstash?  
Here is the flow:  
Elasticsearch -\> logstash -\> csv file

---

<div class="post-metadata">

**Author:** ![Imma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/imma/32/32013_2.png) [@Imma](https://discuss.elastic.co/u/Imma)\
**Post date:** [February 2, 2021, 12:30pm UTC](https://discuss.elastic.co/t/header-in-csv-while-exporting/262958/2 "2021-02-02T12:30:42Z")

</div>

Hi,

I think this is not directly supported. If using `csv_options` in the csv output, you would get a header row for each event. Though I haven't tested it, it's still an open request, so I assume it's not solved: [Add support for CSV header row · Issue #8 · logstash-plugins/logstash-output-csv · GitHub](https://github.com/logstash-plugins/logstash-output-csv/issues/8)

In there the suggested workaround is creating a file first with the headers, and then writing the rows with Logstash. Which might not ideal.

Another workaround seems the one documented here, using ruby [init](https://www.elastic.co/guide/en/logstash/7.10/plugins-filters-ruby.html#plugins-filters-ruby-init) that executes during Logstash startup: [ruby - Logstash - csv output headers - Stack Overflow](https://stackoverflow.com/questions/36097121/logstash-csv-output-headers).

---

<div class="post-metadata">

**Author:** ![ritusingh](https://avatars.discourse-cdn.com/v4/letter/r/ac91a4/32.png) [@ritusingh](https://discuss.elastic.co/u/ritusingh)\
**Post date:** [February 3, 2021, 8:06am UTC](https://discuss.elastic.co/t/header-in-csv-while-exporting/262958/3 "2021-02-03T08:06:41Z")

</div>

Thanks Imma. Just wanted to confirm that logstash is not providing any feature for headers.

---

<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:** [March 3, 2021, 8:07am UTC](https://discuss.elastic.co/t/header-in-csv-while-exporting/262958/4 "2021-03-03T08:07:06Z")

</div>

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