目前,我按照here所述评估了Block Join Children Query Parser。
因此我创建了以下集合:
curl "http://localhost:8983/solr/admin/collections?action=CREATE&name=nestedPerson&numShards=6"`
然后我插入了这两个文件:
curl http://localhost:8983/solr/nestedPerson/update?commitWithin=3000 -d '<add>
<doc>
<field name="id">p1</field>
<field name="deceased">false</field>
<doc>
<field name="id">c1</field>
<field name="firstName">Bob</field>
</doc>
</doc>
<doc>
<field name="id">p2</field>
<field name="deceased">true</field>
<doc>
<field name="id">c2</field>
<field name="firstName">Max</field>
</doc>
</doc>
</add>'
现在我发出这个查询:
{!child of="id:p1"}firstName:Bob
不幸的是,这会导致此错误:
"msg": "Parent query yields document which is not matched by parents filter, docID=0",
如何查询父查询(我猜是部分id:p1
)会产生一个与过滤器不匹配的文档?
答案 0 :(得分:4)
再看一下你再次提到的Solr Wiki here。请注意以下事项:
The syntax for this parser is: q={!child of=<allParents>}<someParents>. The parameter allParents is a filter that matches only parent documents
在您的示例中,查询为{!child of="id:p1"}firstName:Bob
。 id
中使用的字段<allParents>
,但id
包含在父文档和子文档中。
您需要引入仅包含父文档的字段,例如来自Wiki的<field name="content_type">parentDocument</field>
。一旦所有父文档(以及仅父文档)具有此字段,您可以将查询提交为:
q={!parent which="content_type:parentDocument"}firstName:Bob
这将匹配firstName:Bob
的子文档并返回其父项。以类似的方式,使用q={!child of=<allParents>}<someParents>
匹配父文档并返回他们的孩子。