【问题标题】:Solr Indexing My SQL Timestamp or Date Time fieldSolr 索引 My SQL 时间戳或日期时间字段
【发布时间】:2013-04-14 15:46:27
【问题描述】:

要在 Solr 中索引日期,日期应该是 ISO 格式。 我们可以在不修改 SQL Select 语句的情况下索引 MySQL 时间戳或日期时间字段吗?

我用过

 <fieldType name="tdate" class="solr.TrieDateField" omitNorms="true" precisionStep="6"     positionIncrementGap="0"/>

 <field name="CreatedDate" type="tdate" indexed="true" stored="true" />

 CreatedDate is of Type Date Time in MySQL

我得到以下异常

 11:23:39,117 WARN  [org.apache.solr.handler.dataimport.DateFormatTransformer] (Thread-  72) Could not parse a Date field : java.text.ParseException: Unparseable date: "2013-04-14 11:22:48.0"

非常感谢解决此问题的任何帮助

【问题讨论】:

    标签: mysql datetime solr dataimporthandler


    【解决方案1】:

    检查 SOLR 中日期时间字段的默认性质

    DatefieldSOLR

    使用以下 mysql 函数转换您的日期时间值

    SELECT id,DATE_FORMAT(created_at,'%Y-%m-%dT%TZ') as created_at,... from table
    

    【讨论】:

    • 谢谢。它像魔术一样工作。我花了很多时间弄清楚解析异常。即使使用 DateFormatTransformer 也没有解决我的问题。阅读您的解决方案后,我想为什么我没有想到这一点。非常感谢
    猜你喜欢
    • 1970-01-01
    • 2017-08-08
    • 1970-01-01
    • 2010-11-09
    • 2011-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-24
    相关资源
    最近更新 更多