# Write output csv file with header

**URL:** <https://discuss.elastic.co/t/write-output-csv-file-with-header/175311>\
**Category:** Logstash\
**Created:** [April 4, 2019, 4:24am UTC](https://discuss.elastic.co/t/write-output-csv-file-with-header/175311 "2019-04-04T04:24:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sanriya\_Krimzn](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@Sanriya\_Krimzn](https://discuss.elastic.co/u/Sanriya_Krimzn)\
**Post date:** [April 4, 2019, 4:24am UTC](https://discuss.elastic.co/t/write-output-csv-file-with-header/175311/1 "2019-04-04T04:24:40Z")

</div>

Hi there,,,

I am Formatting my input file and writing the formatted input to a .csv file. Using Below code snippet.

output {  
elasticsearch {  
hosts =\> ["localhost:9200"]  
index =\> "Sample\_index"  
document\_type =\> "sample\_doc"  
}  
csv {  
fields =\> ["A", "B", "C"]  
path =\> "output\_path.csv"  
}  
stdout { codec =\> rubydebug }  
}

The above snippet creates an output file with fields "A","B","C".  
**Problem (1)** Output file is created without header. Is there any way to add header??  
_What I tried_ - In csv\_options I gave headers. But header was added before each message which was not expected.  
**Problem (2)** Everytime when I run logstash output is appended to the existing output file. Is there any solution to open a new file for each run of logstash???  
_What I tried_ - In csv\_options I included write\_behaviour =\> overwrite.I didn't get any error. But It didn't work.

---

<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:** [May 2, 2019, 4:24am UTC](https://discuss.elastic.co/t/write-output-csv-file-with-header/175311/2 "2019-05-02T04:24:45Z")

</div>

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