duanbo2048 2019-04-01 18:00
浏览 77

从MySQL导入时如何在solr中保留时区?

I am running solr 7.7.x which imports data including dates from MySQL. In the DB the time is saved to the servers current time zone. After solr imports, it converts to UTC. This leads to a shift of 2h in my case when pulling the data:

MySQL:

"date_created":"2019-04-01 17:18:45"

MySQL import query:

SELECT DATE_FORMAT( c.date_created, '%Y-%m-%dT%H:%i:%sZ' ) AS date_created FROM cls

solr:

"date_created":"2019-04-01T19:18:45Z",

PHP:

date("Y-m-d H:i:s", strtotime($item['date_created']));

I also tried:

$tz = new DateTimeZone('Europe/Berlin');
$date = new DateTime($classified['date_created']);
$date->setTimezone($tz);
$ad['time_created'][$index] = $date->format('Y-m-d H:i:s');

Same result, the time is offset by 2 hours. If I change the DateTimeZone to US, it will offset bei 9h, which shows that at least it has some effect.

I temporarily fixed it by: $ad['time_created'][$index] = date("Y-m-d H:i:s", strtotime($classified['date_created'])-7200); which does not look like a good solution to me.

How can I keep the time from MySQL and what is the recommened approach to deal with timezones in solr?

  • 写回答

1条回答 默认 最新

  • dqxm14187 2019-04-06 16:09
    关注

    I'm not sure whether this will solve your problem or not but you can sync Solr's timezone with MySQL timezone by assigning a timezone to solr, by default solr work on UTC timezone.

    If Solr is on Windows machine, assign timezone as below in solr-x.x.x\bin\solr.in.cmd

    set SOLR_TIMEZONE=<yourTimezone>
    

    and if Solr is on linux, in solr-x.x.x\bin\solr.in.sh

    SOLR_TIMEZONE="<yourTimezone>"
    
    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值