# Unable to output in csv

**URL:** <https://discuss.elastic.co/t/unable-to-output-in-csv/64856>\
**Category:** Logstash\
**Created:** [November 3, 2016, 11:53am UTC](https://discuss.elastic.co/t/unable-to-output-in-csv/64856 "2016-11-03T11:53:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![steve123](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@steve123](https://discuss.elastic.co/u/steve123)\
**Post date:** [November 3, 2016, 11:53am UTC](https://discuss.elastic.co/t/unable-to-output-in-csv/64856/1 "2016-11-03T11:53:18Z")

</div>

I am trying to output CSV of select fields but I am not getting the correct data even with a simplified config  
My config:

> input {  
> generator {  
> add\_field =\> ["foo","bar"]  
> count =\> 1  
> }  
> }  
> output {  
> stdout { codec =\> rubydebug }  
> csv {  
> path =\> "test.csv"  
> fields =\> ["foo"]  
> }  
> }

However my test.only ever contains:  
`2016-11-03T11:07:25.878Z OSTML0204389 Hello world!`

I am expecting it to contain "bar"

Thanks  
Steve

---

<div class="post-metadata">

**Author:** ![Kulasangar\_Gowrisang](https://avatars.discourse-cdn.com/v4/letter/k/ce73a5/32.png) [@Kulasangar\_Gowrisang](https://discuss.elastic.co/u/Kulasangar_Gowrisang)\
**Post date:** [November 3, 2016, 11:56am UTC](https://discuss.elastic.co/t/unable-to-output-in-csv/64856/2 "2016-11-03T11:56:22Z")

</div>

How about having the path outside the `csv` tag like this within the `file` tag:

```
file {
	path => "yourpath/output.csv"
      }

```

Remove the `csv` tag and give it a go. Try inserting your fields parameter within the `file` tag if this works.

---

<div class="post-metadata">

**Author:** ![steve123](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@steve123](https://discuss.elastic.co/u/steve123)\
**Post date:** [November 3, 2016, 12:02pm UTC](https://discuss.elastic.co/t/unable-to-output-in-csv/64856/3 "2016-11-03T12:02:19Z")

</div>

Using just file:

> ```
> input {
> generator {
> add_field => ["foo","bar"]
> count => 1
> }
> }
> output {
> stdout { codec => rubydebug }
> file {
> path => "test.csv"
> }
> }
> 
> ```

produces output:

> `{"sequence":0,"@timestamp":"2016-11-03T12:00:07.986Z","foo":"bar","@version":"1","host":"OSTML0204389","message":"Hello world!"}`

adding fields to a file tag causes a config exception. I really need the csv output as I need to transform select fields into a new csv with a different separator character.

---

<div class="post-metadata">

**Author:** ![Kulasangar\_Gowrisang](https://avatars.discourse-cdn.com/v4/letter/k/ce73a5/32.png) [@Kulasangar\_Gowrisang](https://discuss.elastic.co/u/Kulasangar_Gowrisang)\
**Post date:** [November 3, 2016, 12:06pm UTC](https://discuss.elastic.co/t/unable-to-output-in-csv/64856/4 "2016-11-03T12:06:36Z")

</div>

So in that case your earlier config seems ok according to [this](https://www.elastic.co/guide/en/logstash/current/plugins-outputs-csv.html) if you're using ELK 5.0.

So you're saying it doesn't feed anything into the csv file? Or you're getting any kind of errors?

---

<div class="post-metadata">

**Author:** ![steve123](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@steve123](https://discuss.elastic.co/u/steve123)\
**Post date:** [November 3, 2016, 12:13pm UTC](https://discuss.elastic.co/t/unable-to-output-in-csv/64856/5 "2016-11-03T12:13:38Z")

</div>

Yes using logstash-5.0.0. No Errors are given.

it creates test.csv but contains a single line:

> 2016-11-03T12:09:25.100Z OSTML0204389 Hello world!

The CSV plugin is picking up the option:

> [2016-11-03T12:09:25,040][DEBUG][logstash.outputs.csv] config LogStash::Outputs::CSV/@fields = ["foo"]

---

<div class="post-metadata">

**Author:** ![steve123](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@steve123](https://discuss.elastic.co/u/steve123)\
**Post date:** [November 3, 2016, 12:15pm UTC](https://discuss.elastic.co/t/unable-to-output-in-csv/64856/6 "2016-11-03T12:15:22Z")

</div>

If I generate 5 messages (by changing count to 5) I just get a single long line, so it is not even adding newlines:

> 2016-11-03T12:14:12.816Z OSTML0204389 Hello world!2016-11-03T12:14:12.837Z OSTML0204389 Hello world!2016-11-03T12:14:12.840Z OSTML0204389 Hello world!2016-11-03T12:14:12.842Z OSTML0204389 Hello world!2016-11-03T12:14:12.844Z OSTML0204389 Hello world!

As far as I can tell the logstash-output-csv plugin is not compatible with logstash 5. It defines a receive event that is never called. If I look at the how to define a logstash output plugin it uses multi\_receive. The examples config I have been testing is from the output-csv unit tests. My confidence in using logstash with even its shipped plugins in production has been damaged.

From reading the code for the file ouput plugin it looks like a better way to do CSV output might be to write a new csv codec instead. I will go dig out a ruby tutorial...

---

<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:31am UTC](https://discuss.elastic.co/t/unable-to-output-in-csv/64856/7 "2017-07-06T04:31:16Z")

</div>


