4

Currently I evaluate the Block Join Children Query Parser as described here.

Therefore I have created the following collection:

curl "http://localhost:8983/solr/admin/collections?action=CREATE&name=nestedPerson&numShards=6"`

Then I have inserted these two documents:

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>'

Now I issue this query:

{!child of="id:p1"}firstName:Bob

Unfortunately this results in this error:

"msg": "Parent query yields document which is not matched by parents filter, docID=0",

How can the parent query (I guess that the part id:p1 is meant) yield a document that is not matched by the filter?

siom
  • 1,610
  • 1
  • 14
  • 21

1 Answers1

7

Take a look at the Solr Wiki that you refer to again here. Note the following:

The syntax for this parser is: q={!child of=<allParents>}<someParents>. The parameter allParents is a filter that matches only parent documents

In your example, the query is {!child of="id:p1"}firstName:Bob. The field id as used in<allParents>, but id is contained in both parent and child documents.

You need to introduce a field that only parent documents have, such as <field name="content_type">parentDocument</field> from the wiki. Once all parent documents (and only parent documents) have this field, you could submit the query as:

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

This would match child documents for firstName:Bob and return their parents. In a similar fashion, use q={!child of=<allParents>}<someParents> to match parent documents and return their children.

tkja
  • 1,950
  • 5
  • 22
  • 40
  • I have changed my document such that parent and child document have different fields: ` 1 pd false 2 cd Bob `. Unfortunately I still get the same error when I search for `{!child of=pd:pd}firstName:Bob`. – siom Aug 12 '15 at 06:28
  • Now I have found my problem: The part of the query after the curly brackets is the query on the parent documents and not on the child documents (as the name child suggests). The name child indicates that it returns children. Thanks. – siom Aug 12 '15 at 12:16
  • How should I change the query to get BOTH the matching child and its parent? – P_equals_NP_2021 Dec 27 '19 at 20:25