#community-help

Scoped Search Key with Preset Parameters Issue

TLDR Gustavo faces issues with search key generation and preset parameters. Kishore Nallan clarifies how presets work, but the issue remains unresolved, requiring further investigation.

Powered by Struct AI

1

Jun 13, 2023 (6 months ago)
Gustavo
Photo of md5-f930fdb99fd46477205fa1201164ea50
Gustavo
02:13 PM
How can I generate a scoped search key that limits searching to a specific collection? There's no collection parameter in generateScopedSearchKey().
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
02:17 PM
Use the parent API key to enforce collection limit.
Gustavo
Photo of md5-f930fdb99fd46477205fa1201164ea50
Gustavo
02:18 PM
How do I do that?
02:19
Gustavo
02:19 PM
Found it
Image 1 for Found it
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
02:19 PM
Yes
Gustavo
Photo of md5-f930fdb99fd46477205fa1201164ea50
Gustavo
02:25 PM
Another issue here. The preset contains per_page: 3, but the logged result contains 10 items.
Image 1 for Another issue here. The preset contains `per_page: 3`, but the logged result contains 10 items.Image 2 for Another issue here. The preset contains `per_page: 3`, but the logged result contains 10 items.
02:26
Gustavo
02:26 PM
Also, there's collection: users in the preset, but I can still search on any collection if I try.
02:27
Gustavo
02:27 PM
By the documentation, it seems I should be able to limit the collection in the preset.
Image 1 for By the documentation, it seems I should be able to limit the collection in the preset.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
02:30 PM
> there's collection: users in the preset, but I can still search on any collection if I try.
Does the parent API key of the scoped API key restrict to users collection?
Gustavo
Photo of md5-f930fdb99fd46477205fa1201164ea50
Gustavo
02:33 PM
No, but if the restriction comes from the parent API key, why does the documentation show the parameter collection passed in the preset creation request? Does it serve a different purpose?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
02:45 PM
Preset is just a way for you to store and refer to search params without needing to send them for every search request. If you also pass an explicit collection param in the request, that takes precedence over the preset config.
Gustavo
Photo of md5-f930fdb99fd46477205fa1201164ea50
Gustavo
02:53 PM
Got it, but what about the per_page? The preset sets it to 3 and I'm not passing another value explicitly. Why is it being set to the default 10 anyway?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
04:23 PM
I'm just trying to reproduce this but I'm not able to. Can you post a full snippet? For e..g. here's what I tried: https://gist.github.com/kishorenc/126ae6d3753f3c4441df52b82462ebd4
Gustavo
Photo of md5-f930fdb99fd46477205fa1201164ea50
Gustavo
08:07 PM
Maybe it's an issue in the JS SDK, I'll write a repro
08:09
Gustavo
08:09 PM
No, wait, the preset works when I pass it directly to the search. What doesn't work is the embedded preset in the scoped key.
08:10
Gustavo
08:10 PM
You can see in the attached screenshot here that I'm embedding the preset in the scoped key and then I just use the key, without explicitly passing the preset to the search function.
https://typesense-community.slack.com/archives/C01P749MET0/p1686666301585319?thread_ts=1686665613.494379&cid=C01P749MET0
Jun 14, 2023 (6 months ago)
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
12:01 PM
Let me get back to you on this.

1

Typesense

Lightning-fast, open source search engine for everyone | Knowledge Base powered by Struct.AI

Indexed 3015 threads (79% resolved)

Join Our Community

Similar Threads

Trouble with Scoped Search API Keys in Flutter App

Shane struggled with scoped search API keys in Typesense library for a Flutter app, which returned a 401 error. Jason identified that the error may be a result of an invalid filter within the key, and instructed to create separate keys for different permissions. On implementation, the error was resolved.

1

19
5mo

Issues with Generating Scope API Keys in Python

Danny had issues generating a valid scope API key in a Python GraphQL server. Jason suggested encoding changes and confirmed that the key length varies. Issue unresolved with Python, although JS library worked.

42
19mo

Resolving Issues with Scoped API Keys in Typesense with Golang

Suvarna had problems with generating and using scoped API keys in Typesense with Golang. Several bugs misleading the user were found and fixed by Kishore Nallan.

6

158
28mo

Correct API Key Generation and Usage on Cloud

Tom faced 401 errors while creating keys via the Cloud API. Kishore Nallan clarified the correct syntax and mechanics, and identified a header mislabeling on Tom's part that caused the issue. They also discussed using scoped API keys.

3

31
14mo

Comparing Performance and Security of Different Data Collection Methods

bnfd asked about differences in performance and memory usage between a single, large data collection and multiple smaller collections. Kishore Nallan explained that the latter is faster, suggested 100 collections sharded by user_id, and informed about the use and security of scoped API keys.

1

24
29mo