Bug in Typesense Collection Naming with '#'
TLDR Gabriel identified a bug with using '#' in a Typesense collection name. The issue occurs with collection retrieval in the JS library, even when '#' is URL-encoded. Jason and Adarsh recognized the problem and Gabriel created a Github issue for it.
Mar 10, 2022 (22 months ago)
Gabriel
07:53 PMSo if I create a collection with a # in the name.
I can create the collection using the JS library i.e. "collection_name#region"
The collection list will return that a collection with name "collection_name#region" exists.
But when I call to retrieve the collection, then the message is "Not found"
I tried the same with curl and it seems the same applies. When I tried using curl to delete the collection it seems that the returned message that the "#" is dropped as it returned a message of "No collection with name: "collection_name" "
The curl works if I encode the # to %23
so GET to /collections/collection_name%23region return a collection.
But this doesn't work in the JS library.
Jason
08:49 PMJason
08:49 PMCould you share the JS snippet you used for this?
Gabriel
09:39 PMcreate collection with JS lib.
let schema = {
'name': 'companies#region',
'fields': [
{
'name': 'company_name',
'type': 'string',
'facet': false
},
{
'name': 'date',
'type': 'int32',
'facet': false
},
{
'name': 'country',
'type': 'string',
'facet': true
}
],
'default_sorting_field': 'date'
}
client.collections().create(schema)
step 2)
check it exists
clients.collections().retrieve()
will return that it exists.
step 3)
client.collections('companies#region').retrieve()
returns not found.
step 4)
client.collections('companies%23region').retrieve()
also returns not found.
Mar 11, 2022 (22 months ago)
Adarsh
10:06 AM#
is URL Fragment and is not sent to backend, browser will strip anything that comes after #
before making the request to backend.. if you want to have #
then as you discovered, you need to encode it.. (it may be a bad practice, since there are lot of http client libraries which misbehaves)Gabriel
10:13 AMBut I think this behavior is a bug in a sense that
you can create the a collection with a name with a # without encoding it.
But then in JS lib you can't retrieve the collection, even if you encode the # to %23.
And JS lib is not necessary running in a browser, it might be a lambda function or a nodejs.
Adarsh
10:38 AMGabriel
12:21 PMhttps://github.com/typesense/typesense/issues/548
It's a minor thing, but it was just a bit annoying, that I created a collection and it worked, but then had to go through logs to find out why it was failing when trying to insert documents. 🙂
Jason
07:42 PMTypesense
Indexed 3011 threads (79% resolved)
Similar Threads
Troubleshooting Typesense Connection Issue and Data Retrieval
Felix encountered issues connecting to a server-created typesense and retrieving data collections. Kishore Nallan and Jason provided guidance, highlighting errors in the original code and suggesting changes to the URL and curl command.
Issue with Typesense Schema and Ruby Client
Mateo faces issues while creating a schema and using Ruby client for Typesense. Jason suggests using a new field instead of 'id' and provides assistance for Ruby client errors.
Resolving Typesense Server Connection with Correct API Keys and Paths
Rubai had trouble creating a working API key for Typesense and understanding number_hits versus num_documents. Jason provided clarification and correct code for generating a search-only API Key and using correct server configurations.
Schema Config Issue With Typesense Hosted on Render
Matthias had issues with a schema config on Typesense hosted on Render. Joshua helped troubleshoot, and Matthias resolved the issue by using the external URL.
Using Aliases in Typesense Search Queries
Babin had a question about using aliases in Typesense search queries, specifically when passing collection names. Jason helped identify a misconfiguration and provided guidance, resolving the issue.