2013-07-23 93 views
11

我有一个名为Solr中LocationIndex与字段的索引如下:Solr的复合唯一键

<fields> 
    <field name="solr_id" type="string" stored="true" required="true" indexed="true"/> 
    <field name="solr_ver" type="string" stored="true" required="true" indexed="true" default="0000"/> 
    // and some more fields 
</fields> 
<uniqueKey>solr_id</uniqueKey> 

但现在我要改变架构,以便唯一的密钥必须是复合两个已经存在田solr_idsolr_ver ......东西如下:

<fields> 
    <field name="solr_id" type="string" stored="true" required="true" indexed="true"/> 
    <field name="solr_ver" type="string" stored="true" required="true" indexed="true" default="0000"/> 
    <field name="composite-id" type="string" stored="true" required="true" indexed="true"/> 
    // and some more fields 
</fields> 
<uniqueKey>solr_ver-solr_id</uniqueKey> 

搜索,我发现这是可以通过增加以下内容架构后:(参考:Solr Composite Unique key from existing fields in schema

<updateRequestProcessorChain name="composite-id"> 
    <processor class="solr.CloneFieldUpdateProcessorFactory"> 
    <str name="source">docid_s</str> 
    <str name="source">userid_s</str> 
    <str name="dest">id</str> 
    </processor> 
    <processor class="solr.ConcatFieldUpdateProcessorFactory"> 
    <str name="fieldName">id</str> 
    <str name="delimiter">--</str> 
    </processor> 
    <processor class="solr.LogUpdateProcessorFactory" /> 
    <processor class="solr.RunUpdateProcessorFactory" /> 
</updateRequestProcessorChain> 

所以我改变了模式,最后它看起来像:

<updateRequestProcessorChain name="composite-id"> 
    <processor class="solr.CloneFieldUpdateProcessorFactory"> 
    <str name="source">solr_ver</str> 
    <str name="source">solr_id</str> 
    <str name="dest">id</str> 
    </processor> 
    <processor class="solr.ConcatFieldUpdateProcessorFactory"> 
    <str name="fieldName">id</str> 
    <str name="delimiter">-</str> 
    </processor> 
    <processor class="solr.LogUpdateProcessorFactory" /> 
    <processor class="solr.RunUpdateProcessorFactory" /> 
</updateRequestProcessorChain> 

<fields> 
    <field name="solr_id" type="string" stored="true" required="true" indexed="true"/> 
    <field name="solr_ver" type="string" stored="true" required="true" indexed="true" default="0000"/> 
    <field name="id" type="string" stored="true" required="true" indexed="true"/> 
    // and some more fields 
</fields> 
<uniqueKey>id</uniqueKey> 

但同时增加了文档它给我的错误:

org.apache.solr.client.solrj.SolrServerException: Server at http://localhost:8983/solr/LocationIndex returned non ok status:400, message:Document [null] missing required field: id 

我没有收到在架构中哪些改变需要根据需要工作?

在我添加的文档中,它包含字段solr_versolr_id。通过结合这两个字段(如solr_ver-solr_id),它将如何以及在哪里(solr)创建id字段?

编辑:

this link这给如何引用这条产业链。 Bu我无法理解它将如何在模式中使用?我应该在哪里进行更改?

+0

你可以发表你的DB-data.config文件 – Nipun

回答

10

所以它看起来像你有你的updateRequestProcessorChain正确定义,它应该工作。但是,您需要将此添加到solrconfig.xml文件而不是schema.xml。您提供的附加链接向您展示了如何修改solrconfig.xml文件并将您定义的updateRequestProcessorChain添加到solr实例的当前/update请求处理程序。

所以找做到以下几点:

  1. 将您<updateRequestProcessorChain>你solrconfig.xml中的文件。
  2. 更新您的solrconfig.xml中文件<requestHandler name="/update" class="solr.UpdateRequestHandler">条目,所以它看起来像修改如下:

    <requestHandler name="/update" class="solr.UpdateRequestHandler"> 
        <lst name="defaults"> 
         <str name="update.chain">composite-id</str> 
        </lst> 
    </requestHandler> 
    

这应该然后执行你定义的更新链和新的文件的时候填充id字段被添加到索引。

+0

我按照你的说法更新了,希望这是正确的rect ..但是现在我得到了'CloneFieldUpdateProcessorFactory'的'class not found'错误。此功能不适用于较旧的solr版本吗?我使用的solr的规格是:'Solr Specification Version:3.4.0.2011.09.09.09.06.17','Solr Implementation Version:3.4.0 1167142 - mike - 2011-09-09 09:06:17'。 –

+0

我只看了Solr源代码,不幸的是,'CloneFieldUpdateProcessorFactory'只能在Solr 4.x版本中使用,并且不包含在Solr 3.x版本中。抱歉。 –

+0

我试过了,我得到这个错误文档缺少必需的uniqueKey字段:composite-id。我们是否需要在文档 – Nipun

4

上述解决方案可能会有一些限制,如果由于连接字段太长而导致“dest”超过最大长度,该怎么办? 还设有MD5Signature一个更溶液(能够产生从一组指定的文档字段的级联的签名串的类,用于128位散列对于精确副本检测)

<!-- An example dedup update processor that creates the "id" field on the fly 
    based on the hash code of some other fields. This example has 
    overwriteDupes set to false since we are using the id field as the 
    signatureField and Solr will maintain uniqueness based on that anyway. --> 
<updateRequestProcessorChain name="dedupe"> 
    <processor class="org.apache.solr.update.processor.SignatureUpdateProcessorFactory"> 
    <bool name="enabled">true</bool> 
    <bool name="overwriteDupes">false</bool> 
    <str name="signatureField">id</str> 
    <str name="fields">name,features,cat</str> 
    <str name="signatureClass">org.apache.solr.update.processor.Lookup3Signature</str> 
    </processor> 
    <processor class="solr.LogUpdateProcessorFactory" /> 
    <processor class="solr.RunUpdateProcessorFactory" /> 
</updateRequestProcessorChain> 

从这里:http://lucene.472066.n3.nabble.com/Solr-duplicates-detection-td506230.html

+0

中定义此复合标识我试过这个解决方案,但它仍然给我Document缺少必需的uniqueKey“id” – Nipun