Wednesday, December 31, 2014

Insert into Solr (Using PHP) throws Invalid Date String:'' Error

In attempt of inserting some data into Solr using PHP i face this error

[Thu Jan 01 02:27:18.513778 2015] [:error] [pid 4766] [client 127.0.0.1:50488] PHP Fatal error:  Uncaught exception 'SolrClientException' with message 'Unsuccessful update request. Response Code 400. <?xml version="1.0" encoding="UTF-8"?>\n<response>\n\n<lst name="responseHeader">\n  <int name="status">400</int>\n  .......................

In attempt of finding solution i come across this point that

Documentation of Date accepted by Solr is

http://lucene.apache.org/solr/4_4_0/solr-core/org/apache/solr/schema/DateField.html

So,fix in PHP code is

Instead of using

date("Y-m-d H:i:s")

I needed to use something like this

gmdate("Y")."-".gmdate("m")."-".gmdate("d")."T".gmdate("H").":".gmdate("i").":".gmdate("s")."Z"

So that date should be in format as accepted by Solr.

Ref
-----
http://stackoverflow.com/questions/18831782/solr-invalid-date-string-exception

No comments: