我正在尝试运行 block 连接查询来提取子文档,但收到“父查询生成与父过滤器不匹配的文档”错误。 我使用的是 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"}
来获取这些 parent 的 child ,所以我现在拥有:
{!child of="content_type:parentDocument"}+name:product +content_type:parentDocument
这按预期工作。
类似地,相反的情况是:
{!parent which="content_type:parentDocument"}+name:product +content_type:childDocument
获取 name:product
child 的 parent
关于solr - 如何查询 Solr 的子文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38659654/