#community-help

Creating Scoped API Keys for Multi-Tenant Doc Search

TLDR David needed help creating scoped API keys for multi-tenant document search. Jason suggested using filter_by: docsearch:$NAME:=12345 and renaming a field to end with _tag to resolve David's challenges. They also discussed documenting this solution.

Powered by Struct AI
9
23mo
Solved
Join the chat
Dec 02, 2021 (23 months ago)
David
Photo of md5-38d8dfef0bf0d903bc30bba3b535298e
David
01:05 AM
👋 Is there a good way to create scoped API keys for doc search? I know you can add attributes to a doc search collection via <meta name="docsearch:$NAME" content="12345" /> but you can't seem to filter on these - only facet by. Use case is multi tenant doc search - am I better off creating a collection for each site?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
01:07 AM
David Yes, you can definitely used scoped API keys for this, and embed filter_by: docsearch:$NAME:=12345 when generating the key
01:08
Jason
01:08 AM
I'd recommend creating one parent key per tenant and then generating a scoped api key for each tenant, this way it's easy to rotate the parent api key for a particular tenant if needed in the future
David
Photo of md5-38d8dfef0bf0d903bc30bba3b535298e
David
01:21 AM
I get Server said: Could not find a filter field named servId in the schema. but see it in hits when I search without the filter.
{
...
id: '5',
    item_priority: 5,
    no_variables: true,
    objectID: '17d9155cd183c02e8c0b9b59f57c1cb23820b556',
    servId: '12345',
    tags: [],
    type: 'content',
...
}
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
01:32 AM
Could you rename the field to end with _tag and run the scraper again?

Only those fields get picked up in the schema by the scraper: https://github.com/typesense/typesense-docsearch-scraper/blob/7a2f05831bc5569e6c19e311125cb0ce91c61b1f/scraper/src/typesense_helper.py#L47
David
Photo of md5-38d8dfef0bf0d903bc30bba3b535298e
David
01:37 AM
That did it - thank you!
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
01:37 AM
🙌
01:38
Jason
01:38 AM
We should probably document this somewhere. Mind doing a PR adding this to the docs here: https://typesense.org/docs/guide/docsearch.html#option-a-docusaurus-powered-sites
David
Photo of md5-38d8dfef0bf0d903bc30bba3b535298e
David
04:31 PM
Will do in the next few days!