2013-05-05 76 views
0

关于类似主题有几个问题,但他们的解决方案似乎不符合我的情况。Solr失败并显示“丢失了所需的唯一密钥ID”错误

ENV:Solr4.2.1下,Tomcat 7

我试图索引公共movielens数据,并开始(因为每个人都)与 '示例' 的核心。我已删除从架构不相关的一些领域给我,并加入其他人指数movielens领域:

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

<!-- fields for u.data in the grouplens data --> 
<field name="user_number" type="string" indexed="true" stored="true" multiValued="false" /> 
<field name="item_number" type="text_general" indexed="true" stored="true"/> 
<field name="rating" type="int" indexed="true" stored="true" /> 
<field name="timestamp" type="date" indexed="true" stored="true"/> 
<!-- end of fields for u.data in the grouplens data --> 
<!-- fields for u.user in the grouplens data , userid is already specified above --> 
<field name="age" type="int" indexed="true" stored="true" /> 
<field name="gender" type="text_general" indexed="true" stored="true"/> 
<field name="occupation" type="text_general" indexed="true" stored="true"/> 
<field name="zipcode" type="text_general" indexed="true" stored="true"/> 
<!-- end of fields for u.user in the grouplens data --> 
... 
<uniqueKey>id</uniqueKey> 

我加入我的Java索引的所有领域,包括生成的“ID”字段,我也印出每个字段我加入,所以从控制台输出下面你可以看到,我确实添加“ID”字段,与人相处......然而,我收到以下错误:

May 5, 2013 9:43:06 AM org.apache.solr.client.solrj.impl.HttpClientUtil createClient 
INFO: Creating new http client, config:maxConnections=128&maxConnectionsPerHost=32&followRedirects=false 
indexUserData() started for file: u.user 
indexUserData() processing line: 1|24|M|technician|85711 
adding field: [user_number, 1] 
adding field: [id, u_user_1] 
adding field: [age, 24] 
adding field: [gender, M] 
adding field: [occupation, technician] 
adding field: [zipcode, 85711] 
Exception in thread "main" org.apache.solr.common.SolrException: Document is missing mandatory uniqueKey field: id 
at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:404) 

任何想法我错过了什么? 谢谢! 滨海

回答

0

你有一个

<uniqueKey>id</uniqueKey> 

下方的<fields>标签在你的架构?您需要在schema.xml中告诉solr,哪个字段将成为您唯一的密钥。

+0

是的,我确实 - 对不起,我没有将该部分包含到模式片段中。我会更新原来的问题。 – Marina 2013-05-05 15:10:37

0

没关系 - 这是一个非常令人尴尬的错误......我在处理每一行时循环了一些标记,并且由于错误,我有声明在循环内部创建新的SolrInputDocument(),而不是外部,所以我是基本上每个字段创建一个新的文档....现在一切正常!