2012-04-17 119 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" />