Is it possible to do a reference inside of a filte...
# community-help
a
Is it possible to do a reference inside of a filter_by? This currently works
Copy code
"filter_by": "((($meetingShares(userId:=mhvRsyKrPb5qEoPn6KB3) || $meetingShares(groupId:=[1, 2, 3])) || folderId:= [1,2,3]) && tenantId:= xUbTDW0Ujk1OK9jpn2BO) && accountId:=bankPiUzRjCGAknd1Ktq",
What id like to do is filter based on a field like accountName, the meeting has a reference to the folders collection which has a string field on a folder called accountName.
Copy code
"filter_by": "((($meetingShares(userId:=mhvRsyKrPb5qEoPn6KB3) || $meetingShares(groupId:=[1, 2, 3])) || folderId.accountName:= [1,2,3]) && tenantId:= xUbTDW0Ujk1OK9jpn2BO) && accountId:=bankPiUzRjCGAknd1Ktq",
This is the config of the folderId field on the meetings collection:
Copy code
{
  "facet": false,
  "index": true,
  "infix": false,
  "locale": "",
  "name": "folderId",
  "optional": true,
  "reference": "folders.id",
  "sort": false,
  "stem": false,
  "type": "string"
}
This is the config of the accountName field on the folders collection
Copy code
{
  "facet": false,
  "index": true,
  "infix": false,
  "locale": "",
  "name": "accountName",
  "optional": false,
  "sort": false,
  "stem": false,
  "type": "string"
}
h
Are you searching on
folders
collection?
a
no we would be searching on a meeting.
message has been deleted
h
Also, does
meetings
references
meetingShares
?
Also, which collection has
accountName
field?
a
folders
h
$folders(accountName: foo)
should work.
You can simplify the filter_by like:
Copy code
$meetingShares(userId:=mhvRsyKrPb5qEoPn6KB3 || groupId:=[1, 2, 3])
Do you want to join only those folders that match the meetingShares?
a
Even a simpler way to look at it would be. where i want to search the meetings collection, which has a field on it called folderId (which is a reference field to the folders collection) and i want to only show meetings where the status field (which resides on the folders collection) is equal to active and the color (which resides on the meetings collection) is equal to blue
Copy code
"filter_by": "color:=blue && folderId.status:=active",
h
Okay. So you can achieve this by:
Copy code
collection: meetings
q: *
filter_by: $folders(status: active) && color: blue
a
Even tho folders have no field on the collection that reference the meeting?
h
Yes the reference field declared in
meetings
will be enough to join in this case.
a
Ok, thats really cool!
is there a way to reindex joins? im not sure the exact cause but it seems like sometimes i have to just delete the collection and then re add it (exactly the same, and with the exact same records in it, to get around this error `Failed to join on `meetingShares`: No reference field found.`
h
It could be related to restarting your typesense instance. Can you check if that's the case?
a
so it looks like it was caused by deleteing the “parent” collection and re adding it back. is there any way to reindex the child collections in that case, without removing and re adding all of the documents in it?
h
If you want to reindex data without hiccups, I suggest you set up aliases.
a
but, is there any way to fix the joins without fully re adding the child documents?
h
Since you are deleting the parent collection entirely, no.
a
but if we are adding it back, exactly the same and adding in all of the exact same documents, in theory then if there was a way to fix the joins the data should work?
h
It is not possible currently. Is this going to be your regular work flow?