【问题标题】:Filter child documents and retrieve the parent+child document过滤子文档并检索父+子文档
【发布时间】:2018-06-18 20:59:46
【问题描述】:

我的 Solr 服务器中有一个简单的文档:

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

我想过滤此文档以仅检索“Alice”文档以及父文档,不包括另一个子文档“Bob”。

预期结果:

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

为此,我使用以下查询:

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

问题是:这个过滤器只返回 Alice 子文档,没有对应的父父文档。

如何解决此搜索问题?我试过使用parentFilter=type:dad,就像建议的here一样,但是这个查询抛出了我无法理解的an error

父查询不能匹配除父过滤器之外的任何文档。将它们组合为 must (+) 和 must-not (-) 子句以查找问题文档。 docID=0

另外,如果我过滤:

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

我会得到两份文件:dad + Alice,而不是一份有 dad->Alice 的文件

【问题讨论】:

  • [child ... childFilter=name:Alice] 怎么样?

标签: solr


【解决方案1】:

您可以将childFilterparentFilter 一起使用:

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

结果:

"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"]
                }
            ]
        }
    ]
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-18
    • 1970-01-01
    • 2019-07-13
    • 1970-01-01
    • 2019-06-25
    • 2013-03-19
    • 2023-03-20
    • 2020-12-29
    相关资源
    最近更新 更多