# Logstash unable to convert date to string correctly

**URL:** <https://discuss.elastic.co/t/logstash-unable-to-convert-date-to-string-correctly/82499>\
**Category:** Logstash\
**Created:** [April 16, 2017, 10:24am UTC](https://discuss.elastic.co/t/logstash-unable-to-convert-date-to-string-correctly/82499 "2017-04-16T10:24:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![niels1189](https://avatars.discourse-cdn.com/v4/letter/n/a698b9/32.png) [@niels1189](https://discuss.elastic.co/u/niels1189)\
**Post date:** [April 16, 2017, 10:24am UTC](https://discuss.elastic.co/t/logstash-unable-to-convert-date-to-string-correctly/82499/1 "2017-04-16T10:24:36Z")

</div>

Elasticsearch version: 5.3.0

Plugins installed: N/A - (Elasticsearch, Kibana & Logstash setup)

JVM version: 1.8.0\_121

OS version: Ubuntu 16.04.2 LTS

Description of the problem including expected versus actual behavior: Expected conversion from date to string to allow parsing of invalid dates.

Steps to reproduce:

Attempt to import data with valid & invalid dates (i.e. 2017-11-31, 0000-00-00, 1926-02-29)  
Attempt conversion from date to string using mutate or csv-\>convert  
Configuration Logstash:  
input {  
stdin {  
type =\> "csv"  
}  
}  
filter {  
csv {  
columns =\> ["email","phone","firstname","lastname","dob"]  
separator =\> ","  
remove\_field =\> ["message","@timestamp","path","type","host"]  
}  
mutate {  
convert =\> { "dob" =\> "string" }  
}  
}  
output {  
elasticsearch {  
action =\> "index"  
hosts =\> ["192.168.1.39:9200"]  
index =\> "contacts"  
}  
}

Provide logs (if relevant):  
logstash.outputs.elasticsearch - Failed action. {:status=\>400, :action=\>["index", {:\_id=\>nil, :\_index=\>"contacts", :\_type=\>"logs", :\_routing=\>nil}, %{host} %{message}], :response=\>{"index"=\>{"\_index"=\>"contacts", "\_type"=\>"logs", "\_id"=\>"AVtZJ7--dwIRdbC4em9f", "status"=\>400, "error"=\>{"type"=\>"mapper\_parsing\_exception", "reason"=\>"failed to parse [dob]", "caused\_by"=\>{"type"=\>"illegal\_field\_value\_exception", "reason"=\>"Cannot parse "1976-11-31": Value 31 for dayOfMonth must be in the range [1,30]"}}}}}

Extra Info:  
I want to insert some user-entered data, but when collecting them we only made sure the months were 1-12 and days were 1-31. We did not check if the date actually existed. Some users had said they'd rather not enter their date of birth (dob) and because of that MySQL added the default 0000-00-00.

Now I want to insert that data into elasticsearch without losing the invalid fields, from what I can see it is unable to convert the date to a string (thus ignoring the parse requirements). Resulting in loss of data.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [April 17, 2017, 4:50am UTC](https://discuss.elastic.co/t/logstash-unable-to-convert-date-to-string-correctly/82499/2 "2017-04-17T04:50:43Z")

</div>

You will need to directly set that mapping in ES, cause it can tell it's a date and tries to dynamically map it like you are seeing.

---

<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 15, 2017, 4:52am UTC](https://discuss.elastic.co/t/logstash-unable-to-convert-date-to-string-correctly/82499/3 "2017-05-15T04:52:16Z")

</div>

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