Solr not saving time in UTC format
If I had defined a field o开发者_运维技巧f type Solr.DateField, I read SOLR always saves it in GMT. But I see that SOLR just takes the time that is in defined in my DB and writes it without conversion.
Is there any configuration parameter for it?
As far as I know the ONLY dateformat SOLR will accept is:
YYYY-MM-DDTHH:MM:SS.000Z (The Z is important!)
in my case, our server is set to non UTC time. when solr retrieves a row from the database, it automatically converts that time to UTC.
the problem is the data that is stored in DB is already in UTC. but because when solr pulls that data, it does another conversion to UTC....
the right way for our purposes (in my opinion) is to have the server set to UTC timezone... but alas, that would mess the entire server farm up... i don't do ops, and i do not know the ramifications. in any case, I'm trying to find a way to resolve this in my code.
As Mauricio Scheffer states, SOLR doesn't care about timezones, which is frustrating.
BUT! If you have a non-UTC time and you know the timezone when you index the value, you can convert it to UTC on the fly in your SOLR update:
"2013-02-07T11:21:51Z+8HOUR"
This looks a bit weird, but adding "Z+8HOUR" to a PST timestamp will convert it to the correct value in UTC. In general, you can use any DateMath modifier when indexing a timestamp.
As far as I know Solr stores dates exactly as you feed it, disregarding any timezone information. It's up to you to convert from/to UTC. Here's a forum thread that confirms this.
For example, here are some conversion routines for PHP.
Ok I found out that the date I am giving to SOLR does not have timezone set in it and in such a case it defaults to whatever timezone the machine is set to.
精彩评论