[英]How to query Solr for child documents
我正在嘗試運行塊聯接查詢以提取子文檔,但出現“父查詢產生的文檔與父母過濾器不匹配”的錯誤。 我正在使用Solr 5.5
我的架構如下所示:
<field name="url" type="string" indexed="true" stored="true" required="true" multiValued="false" />
<field name="name" type="text_en" indexed="true" stored="true" required="true" multiValued="false" />
<field name="content_type" type="string" indexed="true" stored="true" required="true" multiValued="false" />
<uniqueKey>url</uniqueKey>
插入語句如下所示:
{
"url": "http://www.test.com/index.html",
"name": "parent product",
"content_type": "parentDocument",
"_childDocuments_": [
{
"url": "http://www.test.com/index2.html",
"name": "child product",
"content_type": "childDocument"
},
{
"url": "http://www.test.com/index3.html",
"name": "child product 2",
"content_type": "childDocument"
}
]
}
在控制台中運行標准的*:*
查詢會拉回3個文檔,並顯示子項屬於其父項:
{
"docs": [
{
"url": "http://www.test.com/index2.html",
"name": "child product",
"content_type": "childDocument",
"_root_": "http://www.test.com/index.html"
},
{
"url": "http://www.test.com/index3.html",
"name": "child product 2",
"content_type": "childDocument",
"_root_": "http://www.test.com/index.html"
},
{
"url": "http://www.test.com/index.html",
"name": "test product",
"content_type": "parentDocument",
"_version_": 1541193313504198700,
"_root_": "http://www.test.com/index.html"
}
]
}
但是,如果我運行q={!child of="content_type:parentDocument"}
,則會得到父文檔,鑒於“ child of”語句,我不會期望它:
{
"responseHeader": {
"status": 0,
"QTime": 0,
"params": {
"q": "{!child of=\"content_type:parentDocument\"}",
"indent": "true",
"wt": "json"
}
},
"response": {
"numFound": 1,
"start": 0,
"docs": [
{
"url": "http://www.test.com/index.html",
"name": "test product",
"content_type": "parentDocument",
"_version_": 1541193313504198656,
"_root_": "http://www.test.com/index.html"
}
]
}
}
但是,如果我添加任何種類的查詢,都會出現錯誤,例如
q={!child of="content_type:parentDocument"}name:product
甚至
q={!child of="content_type:parentDocument"}name:*
“父查詢產生的文檔與父過濾器不匹配,docID = 0”
因此,據我所知,查詢無法返回子文檔。 這幾乎就像一個查詢和一個過濾器。 查詢即name:*
可以匹配不允許的父文檔和子文檔。 我添加了一個額外的過濾器,即+name:product +content_type:parentDocument
以將結果限制為僅父項。 然后,我添加了{!child of="content_type:parentDocument"}
以獲取這些父母的孩子,所以我現在有:
{!child of="content_type:parentDocument"}+name:product +content_type:parentDocument
並且這按預期工作。
類似地,相反的是:
{!parent which="content_type:parentDocument"}+name:product +content_type:childDocument
要讓孩子的父母有name:product
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.