Solr:使用块连接子查询解析器

Solr: Using the Block Join Children Query Parser

目前,我正在按照 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 部分的意思)如何生成与过滤器不匹配的文档?

再看看你引用的Solr Wikihere。请注意以下几点:

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<allParents> 中使用的字段 id,但 id 包含在 parent 和 child 文档中。

你需要引入一个只有parent个文档才有的字段,比如来自wiki的<field name="content_type">parentDocument</field>。一旦所有 parent 个文档(并且只有 parent 个文档)都有此字段,您可以将查询提交为:

q={!parent which="content_type:parentDocument"}firstName:Bob

这将匹配 child 文档 firstName:Bob 和 return 他们的 parent。以类似的方式,使用 q={!child of=<allParents>}<someParents> 匹配 parent 文档和 return 他们的 children.