【问题标题】:Solr fails with "missing required unique key id" errorSolr 因“缺少所需的唯一密钥 ID”错误而失败
【发布时间】:2013-05-05 14:06:03
【问题描述】:

关于类似主题有几个问题,但他们的解决方案似乎不适合我的情况。

环境:Solr4.2.1,Tomcat 7

我正在尝试索引公共电影镜头数据,并(与所有人一样)从“示例”核心开始。我从架构中删除了一些与我无关的字段,并将其他字段添加到索引 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)

知道我错过了什么吗? 谢谢! 玛丽娜

【问题讨论】:

    标签: solr solrj solr4


    【解决方案1】:

    你有没有

    <uniqueKey>id</uniqueKey>
    

    在您的架构中的&lt;fields&gt; 标记下方?您需要在 schema.xml 中告诉 solr,哪个字段将是您的唯一键。

    【讨论】:

    • 是的,我愿意 - 抱歉,我没有将该部分包含在架构片段中。我会更新原来的问题。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-13
      • 1970-01-01
      • 2015-09-27
      • 2020-08-11
      • 2015-11-02
      • 1970-01-01
      • 2017-03-18
      相关资源
      最近更新 更多