Solrj错误添加doc

时间:2012-04-29 22:58:47

标签: solr solrj

我正在关注维基页面上给出的示例,以通过solrj索引页面。我已经尝试了各种方法让这个工作,但不知何故,我不断得到一个看起来像这样的错误:

错误:[doc = 1]非多值字段ID遇到多个值:[1,34d47c153efcf221]

我的架构非常简单(仅供测试)

    <field name="id" type="int" indexed="true" stored="true" required="true" />
    <field name="name" type="string_filename" indexed="true" stored="true" required="true"/>
    <field name="size" type="int" indexed="true" stored="true" required="true"/>
    <field name="created_at" type="date" indexed="true" stored="true"/>
    <field name="updated_at" type="date" indexed="true" stored="true"/>

代码如下所示:

String solrHost = "localhost";
String coreName = "files";
SolrServer solr = null;
try {
    solr = new CommonsHttpSolrServer("http://"+solrHost+":8983/solr/"+coreName);
} catch (Exception e) {
    System.out.println("ERROR:" + e.getMessage());
}

SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", 1);
doc.addField("name", "testfile.pdf");
doc.addField("size", 34234234);

try{
    `solr.add(doc);
}    catch (Exception e) {
    System.out.println("ERROR adding docs: " + e.getMessage());
}

try{
    solr.commit();
} catch (Exception e) {
    System.out.println("commit FAiled.");
}

希望我失踪的事情真是微不足道。任何帮助表示赞赏:)

2 个答案:

答案 0 :(得分:0)

看起来你正试图为id索引2个值,即1和34d47c153efcf221。

答案 1 :(得分:0)

经过多次阅读和实验。我发现了问题所在。为了启用重复数据删除,我需要在模式文件中添加另一个字段。 像

这样的东西
<field name="signature" type="string" stored="true" indexed="true" multiValued="false" / >

然后在我的solrconfig中,我需要在“signatureField”元素中设置此字段“signature”:

 <updateRequestProcessorChain name="dedupe">
   <processor class="solr.processor.SignatureUpdateProcessorFactory">
     <bool name="enabled">true</bool>
     <str name="signatureField">signature</str>
     <bool name="overwriteDupes">false</bool>
     <str name="fields">id,name</str>
     <str name="signatureClass">solr.processor.Lookup3Signature</str>
   </processor>
   <processor class="solr.LogUpdateProcessorFactory" />
   <processor class="solr.RunUpdateProcessorFactory" />

感谢所有贡献的人! :)

相关问题