有没有办法按子文档字段分组并将父字段包含到结果中?想象一下你有
[
{
"id": "p1",
"name": "parent 1",
"_childDocuments_": [
{
"id": "p1c1",
"name": "child1_of_parent1",
"color": "red"
},
{
"id": "p1c2",
"name": "child2_of_parent1",
"color": "yellow"
}
]
},
{
"id": "p2",
"name": "parent 2",
"_childDocuments_": [
{
"id": "p2c1",
"name": "child1_of_parent2",
"color": "yellow"
}
]
}
]
在一个集合中。
现在查询 /select?group=true&group.field=color&group.limit=10 返回
{
"responseHeader":{
"params":{
"group.limit":"10",
"group.field":"color",
"group":"true"
}
},
"grouped":{
"color":{
"matches":3,
"groups":[
{
"groupValue":"red",
"doclist":{"numFound":1,"docs":[
{
"id":"p1c1",
"name":"child1_of_parent1"
}
]
}
},
{
"groupValue":"yellow",
"doclist":{"numFound":2,"docs":[
{
"id":"p1c2",
"name":"child2_of_parent1"
},
{
"id":"p2c1",
"name":"child1_of_parent2"
}
]
}
}
]
}
}
}
但我需要一个包含其父字段的结果,例如
{
"responseHeader":{
"params":{
"group.limit":"10",
"group.field":"color",
"group":"true"
}
},
"grouped":{
"color":{
"matches":3,
"groups":[
{
"groupValue":"red",
"doclist":{"numFound":1,"docs":[
{
"id":"p1c1",
"name":"child1_of_parent1",
"parent":{
"id": "p1",
"name": "parent 1",
}
}
]
}
},
{
"groupValue":"yellow",
"doclist":{"numFound":2,"docs":[
{
"id":"p1c2",
"name":"child2_of_parent1",
"parent":{
"id": "p1",
"name": "parent 1",
}
},
{
"id":"p2c1",
"name":"child1_of_parent2",
"parent":{
"id": "p2",
"name": "parent 2",
}
}
]
}
}
]
}
}
}
我来自关系数据库,这很容易做到。希望solr也有办法。我正在使用 solr 8.7.0