# Add header row to CSV output

**URL:** <https://discuss.elastic.co/t/add-header-row-to-csv-output/50563>\
**Category:** Logstash\
**Created:** [May 20, 2016, 1:45pm UTC](https://discuss.elastic.co/t/add-header-row-to-csv-output/50563 "2016-05-20T13:45:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![astickler](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@astickler](https://discuss.elastic.co/u/astickler)\
**Post date:** [May 20, 2016, 1:45pm UTC](https://discuss.elastic.co/t/add-header-row-to-csv-output/50563/1 "2016-05-20T13:45:21Z")

</div>

Hi,

I need to create date-specific CSV files with logstash, but can't see how to write a header row. Is this even possible?

Thanks,  
Andrew

---

<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:** [May 21, 2016, 5:27pm UTC](https://discuss.elastic.co/t/add-header-row-to-csv-output/50563/2 "2016-05-21T17:27:12Z")

</div>

I guess

```nohighlight
csv {
  ...
  csv_options => {
    "headers" => true
  }
}

```

_should_ work but after reading the code I suspect it won't actually work since Logstash never supplies the CSV library with the names of the fields.

---

<div class="post-metadata">

**Author:** ![astickler](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@astickler](https://discuss.elastic.co/u/astickler)\
**Post date:** [May 23, 2016, 10:54am UTC](https://discuss.elastic.co/t/add-header-row-to-csv-output/50563/3 "2016-05-23T10:54:40Z")

</div>

Magnus,

You are correct – that option does not cause the headers to be written. Does this mean it’s not possible? Feature request?

Thanks,  
Andrew

---

<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:** [May 23, 2016, 1:42pm UTC](https://discuss.elastic.co/t/add-header-row-to-csv-output/50563/4 "2016-05-23T13:42:53Z")

</div>

Yeah, right now it isn't possible. Seems like a reasonable feature request though. Feel free to file a GitHub issue: [https://github.com/logstash-plugins/logstash-output-csv/issues/new](https://github.com/logstash-plugins/logstash-output-csv/issues/new)

---

<div class="post-metadata">

**Author:** ![henrilabarre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/henrilabarre/32/16909_2.png) [@henrilabarre](https://discuss.elastic.co/u/henrilabarre)\
**Post date:** [March 31, 2017, 2:38pm UTC](https://discuss.elastic.co/t/add-header-row-to-csv-output/50563/5 "2017-03-31T14:38:29Z")

</div>

Now you need to add

```
csv_options => {
        "write_headers" => true
        "headers" =>["line1", "line2", "line3","line4","line5"]
}

```

But the bad thing is that it add header for each line, not only on the first one....

---

<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, 4:27am UTC](https://discuss.elastic.co/t/add-header-row-to-csv-output/50563/6 "2017-07-06T04:27:25Z")

</div>


