# Date parse failure - jdbc

**URL:** <https://discuss.elastic.co/t/date-parse-failure-jdbc/230090>\
**Category:** Logstash\
**Created:** [April 28, 2020, 6:59am UTC](https://discuss.elastic.co/t/date-parse-failure-jdbc/230090 "2020-04-28T06:59:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mimimike](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mimimike/32/60397_2.png) [@mimimike](https://discuss.elastic.co/u/mimimike)\
**Post date:** [April 28, 2020, 6:59am UTC](https://discuss.elastic.co/t/date-parse-failure-jdbc/230090/1 "2020-04-28T06:59:26Z")

</div>

Hi,

I've tried to index some docs with logstash using jdbc. But it always fail because it is not able to index date with format yyyyMMdd

input {  
jdbc {  
jdbc\_connection\_string =\> "jdbc:sqlserver://localhost;databaseName=BD;integratedSecurity=false;"  
jdbc\_driver\_class =\> "com.microsoft.sqlserver.jdbc.SQLServerDriver"  
jdbc\_driver\_library =\> "/root/sqljdbc42.jar"  
statement =\> "SELECT \*  
FROM table"  
}  
}

filter {  
mutate {  
copy =\> { "movimientoid" =\> "[@metadata][\_id]"}  
remove\_field =\> ["@timestamp", "movimientoid"]  
}  
}

output {  
elasticsearch {  
hosts =\> "[http://localhost:9200](http://localhost:9200)"  
index =\> "table"  
document\_id =\> "%{[@metadata][\_id]}"  
}  
#stdout{ }  
}

But I always received the same error:

[WARN] 2020-04-27 18:32:49.989 [[main]\>worker0] elasticsearch - Could not index event to Elasticsearch. {:status=\>400, :action=\>["index", {:\_id=\>"25725798", :\_index=\>"movimientos", :\_type=\>"\_doc", :routing=\>nil}, #LogStash::Event:0x4cc06d9e], :response=\>{"index"=\>{"\_index"=\>"movimientos", "\_type"=\>"\_doc", "\_id"=\>"25725798", "status"=\>400, "error"=\>{"type"=\>"mapper\_parsing\_exception", "reason"=\>"failed to parse field [fecha] of type [date] in document with id '25725798'", "caused\_by"=\>{"type"=\>"illegal\_argument\_exception", "reason"=\>"failed to parse date field [2009-04-21T22:00:00.000Z] with format [basic\_date]", "caused\_by"=\>{"type"=\>"date\_time\_parse\_exception", "reason"=\>"date\_time\_parse\_exception: Text '2009-04-21T22:00:00.000Z' could not be parsed at index 4"}}}}}}

I don't know how can i resolve this. Could someone help me??

Furthermore, the SQL query returns the field fecha with yyyy-MM-dd format.

Thanks.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [April 28, 2020, 4:39pm UTC](https://discuss.elastic.co/t/date-parse-failure-jdbc/230090/2 "2020-04-28T16:39:43Z")

</div>

> [@mimimike](#):
>
> "reason"=\>"failed to parse date field [2009-04-21T22:00:00.000Z] with format [basic\_date]", "caused\_by"=\>{"type"=\>"date\_time\_parse\_exception", "reason"=\>"date\_time\_parse\_exception: Text '2009-04-21T22:00:00.000Z' could not be parsed at index 4"

elasticsearch is expecting a basic\_date (yyyyMMdd), which I think has to be due to an index template. If a table contains a date/time type then the jdbc filter will have converted that into a Logstash::Timestamp. The elasticsearch output will have formated that as 2009-04-21T22:00:00.000Z.

You can probably fix this by changing the index template to expect date\_time instead of basic\_date.

---

<div class="post-metadata">

**Author:** ![mimimike](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mimimike/32/60397_2.png) [@mimimike](https://discuss.elastic.co/u/mimimike)\
**Post date:** [April 28, 2020, 6:38pm UTC](https://discuss.elastic.co/t/date-parse-failure-jdbc/230090/3 "2020-04-28T18:38:27Z")

</div>

Could i change the default timestamp to basic date?

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [April 28, 2020, 7:18pm UTC](https://discuss.elastic.co/t/date-parse-failure-jdbc/230090/4 "2020-04-28T19:18:24Z")

</div>

You could use ruby and strftime to format a field, possibly event @timestamp with basic\_date format. However, there is code in logstash that expects @timestamp to be a Logstash::Timestamp, so changing its type may break things.

---

<div class="post-metadata">

**Author:** ![mimimike](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mimimike/32/60397_2.png) [@mimimike](https://discuss.elastic.co/u/mimimike)\
**Post date:** [April 29, 2020, 7:20am UTC](https://discuss.elastic.co/t/date-parse-failure-jdbc/230090/5 "2020-04-29T07:20:42Z")

</div>

Thanks @Badger One doubt more, if finally I record the dates with the default format (2009-04-21T22:00:00.000Z.), could I search in my index using basic\_date format in a range query?

---

<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 27, 2020, 7:27am UTC](https://discuss.elastic.co/t/date-parse-failure-jdbc/230090/6 "2020-05-27T07:27:52Z")

</div>

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