首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从Solr嵌套文档中组合父项和子项

如何从Solr嵌套文档中组合父项和子项
EN

Stack Overflow用户
提问于 2019-10-01 06:14:00
回答 1查看 126关注 0票数 0

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

我已经对嵌套文档进行了索引,如下所示

代码语言:javascript
复制
[
  {
    "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,并列出所有孩子的父母?比如

代码语言:javascript
复制
[
  {
    "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)的所有父项。并且文档的深度不是常量。

EN

回答 1

Stack Overflow用户

发布于 2019-10-01 10:00:25

我目前的解决方案是对数据进行处理,在原始数据中添加跟踪,这样我就可以知道文档来自哪里。比如

代码语言:javascript
复制
[
  {
    "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"
      }
    ]
  }
]

因此,在索引之后,我可以从结果中知道谁是父文档。

有人能同意这一点吗?寻找比这更好的解决方案。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58175910

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档