【问题标题】:how to combine parent and children from Solr nested documents如何结合 Solr 嵌套文档中的父子节点
【发布时间】:2020-01-30 05:19:09
【问题描述】:

我是 lucence、solr 查询的新手,我对如何查询嵌套文档有疑问。

我已将嵌套文档编入索引,如下所示

[
  {
    "id": "1",
    "title": "Solr1",
    "_childDocuments_": [
      {
        "id": "2",
        "title": "Solr2",
        "_childDocuments_": [
          {
            "id": "3",
            "title": "Solr3",
            "_childDocuments_": [
              {
                "id": "4",
                "title": "SolrCloud supports it"
              }
            ],
            "something_else":"irrelevant"
          }
        ],
        "something_else":"irrelevant"
      }
    ],
    "something_else":"irrelevant"
  },
  {
    "id": "5",
    "title": Solr5",
    "_childDocuments_": [
      {
        "id": "6",
        "title": "SolrCloud here as well"
      }
    ]
  }
]

如何搜索标题:SolrCloud,并列出所有孩子的父母?比如

[
  {
    "id": "1",
    "title": "Solr1",
    "_childDocuments_": [
      {
        "id": "2",
        "title": "Solr2",
        "_childDocuments_": [
          {
            "id": "3",
            "title": "Solr3",
            "_childDocuments_": [
              {
                "id": "4",
                "title": "SolrCloud supports it"
              }
            ]
          }
        ]
      }
    ]
  },
  {
    "id": "5",
    "title": Solr5",
    "_childDocuments_": [
      {
        "id": "6",
        "title": "SolrCloud here as well"
      }
    ]
  }
]

列出了文档 4(Sorl1、Solr2、Solr3)和文档 6(Solr5)的所有父项。 而且文档的深度不是常数。

【问题讨论】:

    标签: solr lucene edismax dismax


    【解决方案1】:

    我目前的解决方案是按摩数据,将trace添加到原始数据中,这样我就会知道文件来自哪里。比如

    [
      {
        "id": "1",
        "title": "Solr1",
        "_childDocuments_": [
          {
            "id": "2",
            "title": "Solr2",
            **"parent_id":"1",**
            **"trace":"Solr1",**
            "_childDocuments_": [
              {
                "id": "3",
                "title": "Solr3",
                **"parent_id":"2",**
                **"trace":"Solr1/Solr2",**
                "_childDocuments_": [
                  {
                    "id": "4",
                    "title": "SolrCloud supports it"
                    **"parent_id":"3",**
                    **"trace":"Solr1/Solr2/Solr3",**
                  }
                ],
                "something_else":"irrelevant"
              }
            ],
            "something_else":"irrelevant"
          }
        ],
        "something_else":"irrelevant"
      },
      {
        "id": "5",
        "title": Solr5",
        "_childDocuments_": [
          {
            "id": "6",
            **"parent_id":"5",**
            **"trace":"Solr5",**
            "title": "SolrCloud here as well"
          }
        ]
      }
    ]
    

    所以索引后,我可以从结果中知道谁是父文档。

    有人可以同意吗? 寻找比这更好的解决方案。

    【讨论】:

      猜你喜欢
      • 2020-02-27
      • 2017-03-22
      • 2018-07-26
      • 2018-07-14
      • 2013-05-16
      • 2022-11-07
      • 1970-01-01
      • 2016-07-11
      • 2015-02-07
      相关资源
      最近更新 更多