This message was deleted.
# community-help
s
This message was deleted.
j
It's not possible to do this in a nested array of objects. If the size can be this high, you might want to consider breaking this out into multiple records, and then using group_by to fetch one result from each group
j
Thanks for the fast response. I think I follow what you are saying and see how that would work. Maybe I can explain the problem I'm trying to solve and see if you see another option. I was experimenting with joins today and couldn't see a way forward there.
We want to be able to search across a parent/child relationship simultaneously, lets say fields 1-3 in the document below.
Copy code
{
   "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?
k
I 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?
j
Sure, here is a simplified version of my actual collections:
Copy code
{
  "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:
Copy code
{
  "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
Copy code
// 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.
k
Thanks for the detailed breakdown. We will be looking into this next week. I'll post an update.
h
Hi @James Knight if you only want to query by the parent's name field along with child's name, you can add just the parent name field in each child and do:
Copy code
{
  "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
Copy code
"include_fields": "$parent(*)"
if there are fields with common names in both the collections, you can specify
Copy code
"include_fields": "$parent(*) as parent"
so every field of the parent would have
parent.
as a prefix.