2

I have a simple document in my Solr server:

{
    "id": 1,
    "type": "dad",
    "_childDocuments_": [
        {
            "id": 2,
            "name": "Alice"
        },
        {
            "id": 3,
            "name": "Bob"
        }
    ]
}

I want to filter this document to retrieve only the "Alice" document, along with the parent document, excluding the other child, "Bob".

Expected result:

{
    "id": 1,
    "type": "dad",
    "_childDocuments_": [
        {
            "id": 2,
            "name": "Alice"
        }
    ]
}

For this, I'm using the following query:

q: name:Alice
fl: *, [child parentFilter=*:* limit=10]

The problem is: this filter returns only the Alice child document, without the corresponding dad parent document.

How can I fix this search? I've tried using parentFilter=type:dad, like suggested here, but this query throws an error that I couldn't understand:

Parent query must not match any docs besides parent filter. Combine them as must (+) and must-not (-) clauses to find a problem doc. docID=0

Also, if I filter with:

q: type:dad name:Alice
fl: *, [child parentFilter=*:* limit=10]

I will get two documents: dad + Alice and not one document with dad->Alice

mig
  • 33
  • 7

1 Answers1

0

You can use the childFilter along with the parentFilter:

q= type:dad
fl= *, [child parentFilter=type:dad childFilter=name:Alice limit=10]

Result:

"response": {
    "numFound": 1,
    "start": 0,
    "docs": [
        {
            "id": "1",
            "type": ["dad"],
            "_version_": 1603065478506348544,
            "type_str": ["dad"],
            "_childDocuments_": [
                {
                    "id": "2",
                    "name": ["Alice"],
                    "_version_": 1603065478506348544,
                    "name_str": ["Alice"]
                }
            ]
        }
    ]
}
Zanon
  • 29,231
  • 20
  • 113
  • 126