James Knight
09/23/2023, 1:32 PM{
"name": "parent",
"fields": [
{ "name": "parent_id", "type": "string" },
{ "name": "name", "type": "string" },
]
}
{
"name": "children",
"fields": [
{ "name": "child_id", "type": "string" },
{ "name": "name", "type": "string" },
{ "name": "parent_id", "type": "string", "reference": "parent.parent_id" }
]
}
Based on the current join documentation, it doesn't seem like you can use query_by with a reference collection at all (if I try it hangs), but I'd like to do something like:
{
"q": "abc",
"query_by": "name,$parent(name)",
"collection": "children"
}
A simple solution in my case seems to be just to add all parent fields directly to the children, and have a single collection with the children alone. I can then query across all the fields I want and use group by to aggregate and limit on the parent ID
// collection
{
"name": "children",
"fields": [
{ "name": "child_id", "type": "string" },
{ "name": "name", "type": "string" },
{ "name": "parent_id", "type": "string" },
{ "name": "parent_name", "type": "string" }
]
}
// query
{
"q": "abc",
"query_by": "name,parent_name",
"collection": "children",
"group_by": "parent_id",
"group_limit": 5
}
The only downside I think is that I have to duplicate the parent information across many children, but the collection isn't that large so I don't think this is an issue.