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 Ulul <ha...@ulul.org> on 2017/07/20 00:10:53 UTC

DateRangeField and Timezone

Hi everyone

I'm trying to query on dates with time zone taken into account. I have
the following document

{"date" : "2016-12-31T04:15:00Z", "desc" : "winter time day before" }
date being of type DateRangeField

I would like to be able to perform a query based on local date. For
instance the above date corresponds to 2016-12-30 in New York (UTC-5 in
winter) so I would expect the following query NOT to retrieve the document :

http://127.0.1.1:7574/solr/date_test/select?TZ=America/New_York&indent=on&q=date:2016-12-31&wt=json

Unfortunately it does... and it's the same using filter query

https://cwiki.apache.org/confluence/display/solr/Working+with+Dates
describes how to use TZ in facets, why doesn't it work with simple queries ?

I'm using Solr 6.5.1

I had to add DateRangeField type myself to the collection schema. I did
it with :

curl -X POST -H 'Content-type:application/json' --data-binary '{
  "add-field-type" : {
     "name":"DateRangeField",
     "class":"solr.DateRangeField"
  }
}' http://localhost:7574/solr/date_test/schema

Thank you for your help

Ulul


Re: DateRangeField and Timezone

Posted by Ulul <ha...@ulul.org>.
Hi

Got it thanks to debug option

TZ applies only to date computations, so you have to compute a date :)

The document {"date" : "2016-12-31T04:15:00Z", "desc" : "winter time day
before" }

is retrieved with query date:[2016-12-31T12:15:00Z/DAY TO
2017-01-03T12:15:00Z/DAY]  and "TZ":"Europe/Paris" that translates to
[2016-12-30T23 TO 2017-01-02T23:00:00]

the same query with TZ=America/New_York translates to [2016-12-31T05 TO
2017-01-03T05:00:00] and does not retrives the doc

Cheers

On 20/07/2017 02:10, Ulul wrote:
> Hi everyone
>
> I'm trying to query on dates with time zone taken into account. I have
> the following document
>
> {"date" : "2016-12-31T04:15:00Z", "desc" : "winter time day before" }
> date being of type DateRangeField
>
> I would like to be able to perform a query based on local date. For
> instance the above date corresponds to 2016-12-30 in New York (UTC-5 in
> winter) so I would expect the following query NOT to retrieve the document :
>
> http://127.0.1.1:7574/solr/date_test/select?TZ=America/New_York&indent=on&q=date:2016-12-31&wt=json
>
> Unfortunately it does... and it's the same using filter query
>
> https://cwiki.apache.org/confluence/display/solr/Working+with+Dates
> describes how to use TZ in facets, why doesn't it work with simple queries ?
>
> I'm using Solr 6.5.1
>
> I had to add DateRangeField type myself to the collection schema. I did
> it with :
>
> curl -X POST -H 'Content-type:application/json' --data-binary '{
>   "add-field-type" : {
>      "name":"DateRangeField",
>      "class":"solr.DateRangeField"
>   }
> }' http://localhost:7574/solr/date_test/schema
>
> Thank you for your help
>
> Ulul
>