我是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(的所有父项。 文档的深度不是常量。
我目前的解决方案是按摩数据,将跟踪添加到原始数据中,这样我就会知道文档来自。
如[
{
"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"
}
]
}
]
因此,在索引之后,我可以从结果中知道谁是父文档。
有人可以同意这一点吗? 寻找比这更好的解决方案。