2016-04-13 73 views
2

我正在使用Solr 5.4.0。我已經進口了一些簡單的數據與嵌套文檔:Solr在過濾子文檔時返回不正確的結果

<doc> 
    <field name="id">d1</field> 
    <field name="content_type">parent_document</field> 
    <doc> 
    <field name="id">d2</field> 
    <field name="content_type">related_parent</field> 
    </doc> 
</doc> 
<doc> 
    <field name="id">d3</field> 
    <field name="content_type">parent</field> 
    <doc> 
    <field name="id">d4</field> 
    <field name="content_type">related_parent</field> 
    </doc> 
</doc> 
<doc> 
    <field name="id">d5</field> 
    <field name="content_type">parent</field> 
    <doc> 
    <field name="id">d2</field> 
    <field name="content_type">related_parent</field> 
    </doc> 
</doc> 

字段定義是:

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

<fieldType name="lowercase" class="solr.TextField" positionIncrementGap="100"> 
<analyzer> 
    <tokenizer class="solr.KeywordTokenizerFactory"/> 
    <filter class="solr.LowerCaseFilterFactory"/> 
</analyzer> 

我需要找到具有D2作爲一個子文檔的所有文檔。 我使用查詢:

q={!parent which=content_type:parent}id:d2 

我希望D5作爲結果,而是我得到:

"response": { 
    "numFound": 1, 
    "start": 0, 
    "docs": [ 
    { 
     "id": "d3", 
     "content_type": "parent", 
     "_version_": 1531507509621162000, 
     "_root_": "d3" 
    }, 
    { 
     "id": "d5", 
     "content_type": "parent", 
     "_version_": 1531507848756854800, 
     "_root_": "d5" 
    } 
    ] 
} 

爲什麼這裏返回D3?我應該添加到這個查詢過濾掉d3的條件是什麼?

+0

你發現它爲什麼會發生?我在6.6中看到過類似的情況,但在我們的案例中,我們採取了提琴手捕捉並且看起來都是正確的,但是100個文檔中至少有1個受到了該問題的影響。 – eglasius

回答

0

我可以看到兩件事情會在這裏:

  1. 正如我在https://stackoverflow.com/a/31952527/3229995的回答,現場「CONTENT_TYPE」只應出現在父文件。在以前的Solr版本中,我有一些不一致的行爲,使字段「content_type」在子文檔中存在一些其他值,並且我不知道在當前版本中是否已解決此問題。

  2. 在您的數據集中有兩個id =「d2」的文檔。在Solr中,每個文檔都有一個唯一的標識符,默認情況下這是id字段。集合中不能有兩個具有相同唯一標識符的文檔。

我會建議相應地更改兩個點,使塊連接查詢解析器正常工作。

+1

廣告2,是的,我更改了示例代碼中的字段名稱。在真實數據中,該字段具有其他名稱,所以它不是錯誤的原因。 –

+0

按照1,只在示例中向您的父文檔添加「content_type」字段。那它有用嗎? – tkja