#community-help

Issues with Scoped Search Keys on App

TLDR Sai was having trouble with generating scoped search keys for users on their app. Kishore Nallan helped identify the problem; the userAcl field was not indexable, thus, it needed to be set as indexable.

Powered by Struct AI

1

15
15mo
Solved
Join the chat
Sep 14, 2022 (15 months ago)
Sai
Photo of md5-b9327d0862b35ce6892410a50cfa1514
Sai
12:55 PM
I’m trying to generate scoped search keys for every user on our app from a single parent key.

This new scoped search keys have embedded filters like below
  client.keys().generateScopedSearchKey(searchApiKey, {
    filter_by: `userAcl:=${userId}`,
    exclude_fields: ['userAcl'],
  })
12:56
Sai
12:56 PM
With the parent key, I was able to search collections. But with the scoped search, server’s returning empty results.
12:56
Sai
12:56 PM
Is there something that i need to keep in mind while generating these keys?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:12 PM
Can you post the key here or DM me it if it's not a throw away test key?
Sai
Photo of md5-b9327d0862b35ce6892410a50cfa1514
Sai
01:19 PM
It’s a test key.
01:19
Sai
01:19 PM
M3hyR1VHK2J1QjZzelVHNklxL1R2VFdKQlRoOEltUXI4M2RtODgyTitqZz1WNFA1eyJmaWx0ZXJfYnkiOiJ1c2VyQWNsOj1RUnFZUFFmcHZrYjVZZWZtYnhWN1VSdWcxaDQyIiwiZXhjbHVkZV9maWVsZHMiOlsidXNlckFjbCJdfQ==
01:20
Sai
01:20 PM
This is the parent key - V4P51wT3SDG24LEQs8p9UoccuxDlCGVn
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:20 PM
So the key has {"filter_by":"userAcl:=QRqYPQfpvkb5YefmbxV7URug1h42","exclude_fields":["userAcl"]}

Exclude fields must be a comma separated string.
01:21
Kishore Nallan
01:21 PM
You can see if there are any errors in Typesense server logs. We can't returned detailed errors in the API for auth errors due to security reasons but they will be logged.
Sai
Photo of md5-b9327d0862b35ce6892410a50cfa1514
Sai
01:28 PM
I don’t see any errors in the logs
01:30
Sai
01:30 PM
Even with the above fix - results are still not showing up. Should the field be marked as indexable?
01:33
Sai
01:33 PM
This is the collection schema
{
        "created_at": 1663158468,
        "default_sorting_field": "",
        "fields": [
            {
                "facet": false,
                "index": true,
                "infix": false,
                "locale": "",
                "name": "name",
                "optional": false,
                "sort": false,
                "type": "string"
            },
            {
                "facet": false,
                "index": true,
                "infix": false,
                "locale": "",
                "name": "description",
                "optional": false,
                "sort": false,
                "type": "string"
            },
            {
                "facet": false,
                "index": false,
                "infix": false,
                "locale": "",
                "name": "userAcl",
                "optional": true,
                "sort": false,
                "type": "string[]"
            }
        ],
        "name": "playlists",
        "num_documents": 21,
        "symbols_to_index": [],
        "token_separators": []
    }
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:40 PM
Yes it needs to be indexable
01:40
Kishore Nallan
01:40 PM
When you set index: false it will be stored on disk but no search datastructures will be populated so you can't search, sort or filter.
Sai
Photo of md5-b9327d0862b35ce6892410a50cfa1514
Sai
01:42 PM
Got it. My bad.
Thanks

1

Typesense

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

Indexed 3011 threads (79% resolved)

Join Our Community