2013-07-23 94 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