# CSV date parser failure while uploading it to logstash

**URL:** <https://discuss.elastic.co/t/csv-date-parser-failure-while-uploading-it-to-logstash/84722>\
**Category:** Logstash\
**Created:** [May 5, 2017, 1:31pm UTC](https://discuss.elastic.co/t/csv-date-parser-failure-while-uploading-it-to-logstash/84722 "2017-05-05T13:31:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manjunath.premkumar](https://avatars.discourse-cdn.com/v4/letter/m/278dde/32.png) [@Manjunath.premkumar](https://discuss.elastic.co/u/Manjunath.premkumar)\
**Post date:** [May 5, 2017, 1:31pm UTC](https://discuss.elastic.co/t/csv-date-parser-failure-while-uploading-it-to-logstash/84722/1 "2017-05-05T13:31:37Z")

</div>

Hi , I am stuck in parsing the date field in CSV and tried my best but no luck.

CSV contains 2 fields, Data and Responsetime (separated by comma) and I want to plot graph in KIBANA with x axis as Date and response as Y axis. I am able to load the data to elastic search through logstash but it is failing with Date parsing.

Sample format of CSV  
2017-04-20 10:00:01.789,2  
2017-04-20 10:00:03.061,2  
2017-04-20 10:00:07.247,2  
2017-04-20 10:00:07.471,2

Conf file for uploading, filtering and output

input {  
file {  
path =\> "/home/ubuntu/Logsheet3.csv"  
type =\> "sportium"  
start\_position =\> "beginning"  
}  
}  
filter {  
csv {

columns =\> ["date","responsetime"]  
separator =\> ","  
}  
date {  
match =\> ["date","YYYY-MM-dd HH:mm:ss.SSS","ISO8601"]  
target =\> "@timestamp"  
}  
mutate {  
convert =\> ["responsetime", "float"]  
}  
}  
output {  
elasticsearch {  
hosts =\> ["localhost:9200"]  
index =\> "sportiumcsv"  
}  
stdout { codec =\> rubydebug }  
}

Jsonoutput in elasticsearch

{  
"\_index": "sportiumcsv",  
"\_type": "sportium",  
"\_id": "AVvYodnHbFL5xGFaJABg",  
"\_version": 1,  
"\_score": null,  
"\_source": {  
"date": "2017-04-20 10:59:59.192,1",  
"path": "/home/ubuntu/Logsheet3.csv",  
"@timestamp": "2017-05-05T12:42:17.394Z",  
"@version": "1",  
"host": "ip-172-31-1-97",  
"message": ""2017-04-20 10:59:59.192,1"\r",  
"type": "sportium",  
"tags": [  
"\_dateparsefailure"  
]  
},  
"fields": {  
"@timestamp": [  
1493988137394  
]  
},  
"sort": [  
1493988137394  
]  
}

---

<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 7, 2017, 7:27pm UTC](https://discuss.elastic.co/t/csv-date-parser-failure-while-uploading-it-to-logstash/84722/2 "2017-05-07T19:27:07Z")

</div>

Why is there a trailing ",1" in the `date` field? And where's the `responsetime` field? Aha. Your `message` field is double-quoted, so the csv filter (correctly) assumes that the input contains a single column. You can use the mutate filter and its gsub option to remove the quotes, but it would be better to fix the problem at the source.

---

<div class="post-metadata">

**Author:** ![Manjunath.premkumar](https://avatars.discourse-cdn.com/v4/letter/m/278dde/32.png) [@Manjunath.premkumar](https://discuss.elastic.co/u/Manjunath.premkumar)\
**Post date:** [May 8, 2017, 6:16am UTC](https://discuss.elastic.co/t/csv-date-parser-failure-while-uploading-it-to-logstash/84722/3 "2017-05-08T06:16:19Z")

</div>

Thanks Magnus

CSV file as 2 column data- Date and responsetime which is separated by comma. I will try to correct the CSV file content to get ride of the double quotes and let you know whether it worked out.

Thanks,  
Manju

---

<div class="post-metadata">

**Author:** ![Manjunath.premkumar](https://avatars.discourse-cdn.com/v4/letter/m/278dde/32.png) [@Manjunath.premkumar](https://discuss.elastic.co/u/Manjunath.premkumar)\
**Post date:** [May 8, 2017, 7:44am UTC](https://discuss.elastic.co/t/csv-date-parser-failure-while-uploading-it-to-logstash/84722/4 "2017-05-08T07:44:00Z")

</div>

Hi Magnus,

I tried below gsub mutate it didn't work, can you please guide me here.

I found the source from : [http://stackoverflow.com/questions/22534325/syntax-for-a-grok-mutate-gsub-to-replace-double-quotes-with-single-quotes/22548499#22548499](http://stackoverflow.com/questions/22534325/syntax-for-a-grok-mutate-gsub-to-replace-double-quotes-with-single-quotes/22548499#22548499)

I am not replacing with single quotes but trying to get rid of double quotes inserted by CSV

filter {  
mutate {  
gsub =\> ["message",""",""]  
}  
}

Below is full conf file data, but no luck

input {  
file {  
path =\> "/home/ubuntu/Logsheet3.csv"  
type =\> "sportium"  
start\_position =\> "beginning"  
}  
}

filter {  
csv {

columns =\> ["timestamp","responsetime"]  
separator =\> ","  
}  
mutate {  
gsub =\> ["message",""",""]  
convert =\> ["responsetime", "float"]  
}  
date {  
match =\> ["timestamp", "YYYY-MM-dd HH:mm:ss.SSS", "ISO8601"]  
target =\> "@timestamp"  
}  
}

output {  
elasticsearch {  
hosts =\> ["localhost:9200"]  
index =\> "sucess-%{+YYYY.MM.dd}"  
}  
stdout { codec =\> rubydebug }  
}

Thanks,  
Manju

---

<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 8, 2017, 8:23am UTC](https://discuss.elastic.co/t/csv-date-parser-failure-while-uploading-it-to-logstash/84722/5 "2017-05-08T08:23:52Z")

</div>

Try this:

```
gsub => ['message', '"', '']
```

---

<div class="post-metadata">

**Author:** ![Manjunath.premkumar](https://avatars.discourse-cdn.com/v4/letter/m/278dde/32.png) [@Manjunath.premkumar](https://discuss.elastic.co/u/Manjunath.premkumar)\
**Post date:** [May 8, 2017, 10:34am UTC](https://discuss.elastic.co/t/csv-date-parser-failure-while-uploading-it-to-logstash/84722/6 "2017-05-08T10:34:24Z")

</div>

I tried it but still had issues. So corrected at source by opening the CSV in notepad++ and removed the double quotes and saved it. then used it below code it worked perfectly!!

input {  
file {  
path =\> "/home/ubuntu/Logsheet4.csv"  
type =\> "Success"  
start\_position =\> "beginning"  
}  
}

filter {  
csv {  
columns =\> ["timestamp","responsetime"]  
separator =\> ","  
}  
mutate {  
convert =\> ["responsetime", "float"]  
}  
date {  
match =\> ["timestamp", "YYYY-MM-dd HH:mm:ss.SSS", "ISO8601"]  
target =\> "@timestamp"  
}  
}

output {  
elasticsearch {  
hosts =\> ["localhost:9200"]  
index =\> "succesful-%{+YYYY.MM.dd}"  
}  
stdout { codec =\> rubydebug }  
}

---

<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 5, 2017, 10:35am UTC](https://discuss.elastic.co/t/csv-date-parser-failure-while-uploading-it-to-logstash/84722/7 "2017-06-05T10:35:32Z")

</div>

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