You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Mirko Torrisi <mi...@ucdconnect.ie> on 2015/03/10 20:33:57 UTC

Invalid Date String:'1992-07-10T17'

Hi all,

I am very new with Solr (and Lucene) and I use the last version of it.
I do not understand why I obtain this:

    Exception in thread "main"
    org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error
    from server at http://localhost:8983/solr/Collection1: Invalid Date
    String:'1992-07-10T17'
         at
    org.apache.solr.client.solrj.impl.HttpSolrClient.executeMethod(HttpSolrClient.java:558)
         at
    org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:214)
         at
    org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:210)
         at
    org.apache.solr.client.solrj.request.QueryRequest.process(QueryRequest.java:91)
         at
    org.apache.solr.client.solrj.SolrClient.query(SolrClient.java:302)
         at Update.main(Update.java:18)


Here the code that creates this error:

             SolrQuery query = new SolrQuery();
             String a = "speechDate:1992-07-10T17:33:18Z";
             query.set("fq", a);
             //query.setQuery( a );  <-- I also tried using this one.



According to 
https://cwiki.apache.org/confluence/display/solr/Working+with+Dates, it 
should be right. I tried with others date, or just |YYYY-MM-DD, with no 
success.


My goal is to group these speeches (hopefully using date math syntax). I 
would like to know if you suggest me to use date or tdate or other 
because I have not understood the difference.


Thanks in advance,|

Mirko||

Re: Invalid Date String:'1992-07-10T17'

Posted by Shawn Heisey <ap...@elyograg.org>.
On 3/10/2015 1:39 PM, Ryan, Michael F. (LNG-DAY) wrote:
> You'll need to wrap the date in quotes, since it contains a colon:
>
> String a = "speechDate:\"1992-07-10T17:33:18Z\"";

You could also escape the colons with a backslash.  Here's another way
to do it that doesn't require quotes or manual escaping:

  String d = "1992-07-10T17:33:18Z";
  String a = "speechDate:" + ClientUtils.escapeQueryChars(d);

If you wanted to go to the trouble of using StringBuilder instead of
string concatenation for performance reasons, you could certainly do that.

This is the class you need to import in order to use escapeQueryChars:

http://lucene.apache.org/solr/4_10_2/solr-solrj/org/apache/solr/client/solrj/util/ClientUtils.html

Thanks,
Shawn


RE: Invalid Date String:'1992-07-10T17'

Posted by "Ryan, Michael F. (LNG-DAY)" <mi...@lexisnexis.com>.
You'll need to wrap the date in quotes, since it contains a colon:

String a = "speechDate:\"1992-07-10T17:33:18Z\"";

-Michael

-----Original Message-----
From: Mirko Torrisi [mailto:mirko.torrisi@ucdconnect.ie] 
Sent: Tuesday, March 10, 2015 3:34 PM
To: solr-user@lucene.apache.org
Subject: Invalid Date String:'1992-07-10T17'

Hi all,

I am very new with Solr (and Lucene) and I use the last version of it.
I do not understand why I obtain this:

    Exception in thread "main"
    org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error
    from server at http://localhost:8983/solr/Collection1: Invalid Date
    String:'1992-07-10T17'
         at
    org.apache.solr.client.solrj.impl.HttpSolrClient.executeMethod(HttpSolrClient.java:558)
         at
    org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:214)
         at
    org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:210)
         at
    org.apache.solr.client.solrj.request.QueryRequest.process(QueryRequest.java:91)
         at
    org.apache.solr.client.solrj.SolrClient.query(SolrClient.java:302)
         at Update.main(Update.java:18)


Here the code that creates this error:

             SolrQuery query = new SolrQuery();
             String a = "speechDate:1992-07-10T17:33:18Z";
             query.set("fq", a);
             //query.setQuery( a );  <-- I also tried using this one.



According to
https://cwiki.apache.org/confluence/display/solr/Working+with+Dates, it should be right. I tried with others date, or just |YYYY-MM-DD, with no success.


My goal is to group these speeches (hopefully using date math syntax). I would like to know if you suggest me to use date or tdate or other because I have not understood the difference.


Thanks in advance,|

Mirko||

Re: Invalid Date String:'1992-07-10T17'

Posted by Mirko Torrisi <mi...@ucdconnect.ie>.
Thanks very much for each of your replies. These resolved my problem and 
teach me something important.
I have just discovered that I have another problem but I guess that I 
have to open another discussion.

Cheers,

Mirko

On 10/03/15 20:30, Chris Hostetter wrote:
> ":" is a syntactically significant character to the query parser, so it's
> getting confused by it in the text of your query.
>
> you're seeing the same problem as if you tried to search for "foo:bar" in
> the "yak" field using q=yak:foo:bar
>
> you either need to backslash escape the ":" characters, or wrap the date
> in quotes, or use a diff parser that doesn't treat colons as special
> characters (but remember that since you are building this up as a java
> string, you have to deal with *java* string escaping as well...
>
>     String a = "speechDate:1992-07-10T17\\:33\\:18Z";
>     String a = "speechDate:\"1992-07-10T17:33:18Z\"";
>     String a = "speechDate:" + ClientUtils.escapeQueryChars("1992-07-10T17:33:18Z");
>     String a = "{!field f=speechDate}1992-07-10T17:33:18Z";
>
> : My goal is to group these speeches (hopefully using date math syntax). I would
>
> Unless you are truely seraching for only documents that have an *exact*
> date value matching your input (down to the millisecond) then seraching or
> a single date value is almost certainly not what you want -- you most
> likely want to do a range search...
>
>    String a = "speechDate:[1992-07-10T00:00:00Z TO 1992-07-11T00:00:00Z]";
>
> (which doesn't require special escaping, because the query parser is smart
> enough to know that ":" aren't special inside of the "[..]")
>
> : like to know if you suggest me to use date or tdate or other because I have
> : not understood the difference.
>
> the difference between date and tdate has to do with how you wnat to trade
> index size (on disk & in ram) with search speed for range queries like
> these -- tdate takes up a little more room in the index, but came make
> range queries faster.
>
>
> -Hoss
> http://www.lucidworks.com/


Re: Invalid Date String:'1992-07-10T17'

Posted by Chris Hostetter <ho...@fucit.org>.
":" is a syntactically significant character to the query parser, so it's 
getting confused by it in the text of your query.

you're seeing the same problem as if you tried to search for "foo:bar" in 
the "yak" field using q=yak:foo:bar

you either need to backslash escape the ":" characters, or wrap the date 
in quotes, or use a diff parser that doesn't treat colons as special 
characters (but remember that since you are building this up as a java 
string, you have to deal with *java* string escaping as well...

   String a = "speechDate:1992-07-10T17\\:33\\:18Z";
   String a = "speechDate:\"1992-07-10T17:33:18Z\"";
   String a = "speechDate:" + ClientUtils.escapeQueryChars("1992-07-10T17:33:18Z");
   String a = "{!field f=speechDate}1992-07-10T17:33:18Z";

: My goal is to group these speeches (hopefully using date math syntax). I would

Unless you are truely seraching for only documents that have an *exact* 
date value matching your input (down to the millisecond) then seraching or 
a single date value is almost certainly not what you want -- you most 
likely want to do a range search...

  String a = "speechDate:[1992-07-10T00:00:00Z TO 1992-07-11T00:00:00Z]";

(which doesn't require special escaping, because the query parser is smart 
enough to know that ":" aren't special inside of the "[..]")

: like to know if you suggest me to use date or tdate or other because I have
: not understood the difference.

the difference between date and tdate has to do with how you wnat to trade 
index size (on disk & in ram) with search speed for range queries like 
these -- tdate takes up a little more room in the index, but came make 
range queries faster.


-Hoss
http://www.lucidworks.com/