Slackbot
09/22/2023, 8:34 PMJason Bosco
09/22/2023, 8:35 PMJames Knight
09/22/2023, 8:52 PMJames Knight
09/22/2023, 9:02 PM{
"field1": "abc",
"children": [
{ "field2": "def" },
{ "field3": "geh" },
}
}
I see how this can be done with nesting, but there is the issue of returning too many children. or having to split the document as you suggest. If I separate children into a separate collection, and join them to the parent, I don't see a way to search across both collections at once based on the current specs for joins. But maybe I'm wrong there. Do you see a solution with joining?Kishore Nallan
09/23/2023, 1:19 AMI don't see a way to search across both collections at once based on the current specs for joins.Can you please post the parent child collections that you have created and what query you are now trying to do?
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.Kishore Nallan
09/23/2023, 1:52 PMHarpreet Sangar
09/25/2023, 11:39 AM{
"q": "abc",
"query_by": "name,parent_name",
"collection": "children",
"group_by": "parent_id",
"group_limit": 5
}
parent_id will be the reference field in the child collection. If you want the rest of the fields of the referenced parent to be included in the response, you can send
"include_fields": "$parent(*)"
if there are fields with common names in both the collections, you can specify
"include_fields": "$parent(*) as parent"
so every field of the parent would have parent. as a prefix.