steffen
07/29/2025, 9:01 AMuserId
and a scoped key with that filter.
If we understood the concepts correctly, there is no option to create just one key fulfilling that requirement. Simply since not all collections would have the userId
field (those which are available to all users) and the search on these with that generated scoped key would just yield 0.
So are we indeed required to deal with multiple scoped key per user and decide which one to use based on the query?
How do we tackle that best?steffen
07/29/2025, 9:03 AMKishore Nallan
07/29/2025, 1:02 PMfilter_by
clause). Whatever you embed in that bundle is applied to every search that uses the key and the user can’t override it.
• If you embed filter_by: userId:=123
, the filter will run against all collections referred to by that key.
• Any document (or whole collection) that doesn’t have a userId
field simply fails the filter and never surfaces, so your “public” collections would appear empty.
Because of that, one key cannot simultaneously say “give me every record in collections A, B, C but only a subset of collection D”. You need a way to apply the filter only when you hit the sensitive collection.
Since the multi search request supports API key for each sub-request, you can create 2 API keys, one with the embedded filter and one without and just issue 2 requests like this:
POST /multi_search
X-TYPESENSE-API-KEY: scopedPublic
{
"searches": [
{
"collection": "articles_public",
"q": "kubernetes",
"query_by": "title,body"
// will inherit the top‑level key (scopedPublic)
},
{
"collection": "restricted_docs",
"q": "kubernetes",
"query_by": "title,body",
"x-typesense-api-key": "scopedPrivate" // ONLY this search carries the user filter
}
]
}
steffen
07/29/2025, 1:10 PMGauthier PLM
08/08/2025, 1:42 PMKishore Nallan
08/08/2025, 7:43 PM