2012-04-17 111 views
0

我遇到了solr和mysql日期不佳的问题。如果我从模式中注释掉sent字段,一切正常。但是,只要我在日期字段中添加,我就会为每个文档都收到此错误。从Mysql导入日期到Solr时缺少必填字段

org.apache.solr.common.SolrException: [doc=116] missing required field: sent 

下面是我如何配置solr。我已经确认没有空/空日期,并且没有。我也试过dateTimeFormat = yyyy-MM-dd'T'hh:mm:ss和没有设置dateTimeFormat。我也尝试过在模式中发送的类型的日期和时间。

dataconfig.xml

<dataConfig> 
    <dataSource driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/hoplite" user="root" password="root"/> 
    <document> 
     <entity name="document" query="select * from document"> 
      <field column="ID" name="id" /> 
      <field column="RAW_TEXT" name="raw_text" />  
      <entity name="email" query="select * from email where document_id='${document.id}'">     
       <field column="TIME_SENT" name="sent" dateTimeFormat="yyyy-MM-dd'T'hh:mm:ss'Z'"/> 
       <field column="BODY" name="body" /> 
      </entity> 
     </entity> 
    </document> 
</dataConfig> 

schema.xml中

<field name="id" type="tint" indexed="true" stored="true" required="true" /> 
    <field name="raw_text" type="text_general" indexed="true" stored="false" required="true" multiValued="true"/> 

    <field name="sent" type="date" indexed="true" stored="true" required="true" /> <!-- Import succeeds if I comment this line out --> 
    <field name="body" type="text_general" indexed="true" stored="true" required="true" /> 

回答

0

显然对于日期的字段名称必须是一样的列名。因此,将文件更改为下面的问题可以解决问题。请注意,time_sent现在既是列名也是字段名。

数据-config.xml中

<dataConfig> 
    <dataSource driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/hoplite" user="root" password="root"/> 
    <document> 
     <entity name="document" query="select * from document"> 
      <field column="ID" name="id" /> 
      <field column="RAW_TEXT" name="raw_text" /> 

      <entity name="email" query="select * from email where document_id='${document.id}'">     
       <field column="TIME_SENT" name="time_sent" dateTimeFormat="yyyy-MM-dd'T'hh:mm:ss'Z'"/> 
       <field column="BODY" name="body" /> 
      </entity> 
     </entity> 
    </document> 
</dataConfig> 

schema.xml中

<field name="id" type="tint" indexed="true" stored="true" required="true" /> 
    <field name="raw_text" type="text_general" indexed="true" stored="false" required="true" multiValued="true"/> 

    <field name="time_sent" type="date" indexed="true" stored="true" required="true" /> <!-- Import succeeds if I comment this line out --> 
    <field name="body" type="text_general" indexed="true" stored="true" required="true" />