使用 Apache Solr 索引 MySQL 数据库表时,我收到以下错误:
org.apache.solr.common.SolrException: Document is missing mandatory uniqueKey field: id
这是什么意思?我该如何解决它?
谢谢你。
这意味着 Solr 正在尝试索引未指定字段 id 的文档。在您的 schema.xml 中,您定义了一个 uniqueKey 字段,Solr 索引的每个文档都需要这样的 id 才能索引。
原因之一肯定是在 Solr 中不应该有 int 类型的 id 字段。它应该始终是字符串。我遇到了同样的问题,因为我将 id 字段定义为整数而不是字符串。
我也有同样的错误。我的表名是 voter ,我使用 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"/>