org.apache.solr.common.SolrException:文档缺少必需的uniqueKey字段:id

时间:2013-06-20 14:56:05

标签: mysql solr4

在使用Apache Solr索引MySQL数据库表时,我收到以下错误:

org.apache.solr.common.SolrException: Document is missing mandatory uniqueKey field: id

这是什么意思?我该如何解决?

谢谢。

3 个答案:

答案 0 :(得分:0)

这意味着Solr正在尝试索引未指定字段ID的文档。在schema.xml中,您已经定义了一个uniqueKey字段,Solr索引的每个文档都需要索引这样的id。

答案 1 :(得分:0)

我有同样的错误。我的表名是选民,我使用了voterid作为唯一的id。但是在我将列名称为voterid更改为id后,它对我有效。 这是我的data-config.xml

<dataConfig>
  <dataSource type="JdbcDataSource"
            driver="com.mysql.jdbc.Driver"
            url="jdbc:mysql://localhost/test"
            user="root"
            password="root" /> 
  <document name="voter">
    <entity name="voter" query="select *  from voter;" >
 <field column="id" name="id"/>    
   <field column="voter_name" name="voter_name"/> 
<field column="age" name="age"/>   
</entity>
  </document>
</dataConfig>


Schema.xml File(I added 2 field , id was already present in the file)

<field name="voter_name" type="string" indexed="true" stored="true"/>

<field name="age" type="int" indexed="true" stored="true"/>

<field name="id" type="string" indexed="true" stored="true"/>

答案 2 :(得分:-1)

其中一个原因必须是在Solr中不应该将id字段作为int。它应该始终是字符串。我遇到了同样的问题,因为我将id字段定义为整数而不是字符串。