Resolving Typesense Server Connection with Correct API Keys and Paths

TLDR 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.

Photo of Rubai
Rubai
Fri, 28 Jul 2023 18:07:57 UTC

is num_documents & number_hits both are same ? Jason

Photo of Jason
Jason
Fri, 28 Jul 2023 18:10:52 UTC

number_hits is not a Typesense param…

Photo of Rubai
Rubai
Fri, 28 Jul 2023 18:19:18 UTC

so , is this the number of record stored on for my particular collection

Photo of Jason
Jason
Fri, 28 Jul 2023 18:20:09 UTC

num_documents in the collection schema is indeed the number of records stored in that particular collection

Photo of Rubai
Rubai
Fri, 28 Jul 2023 18:22:24 UTC

got it . and can you please confirm is this is the curl for generating only search access `curl '' -X POST -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \` `-H 'Content-Type: application/json' \` `-d '{"description":"Admin key.","actions": ["*"], "collections": ["*"]}'`

Photo of Jason
Jason
Fri, 28 Jul 2023 18:23:50 UTC

No that’s an admin key

Photo of Jason
Jason
Fri, 28 Jul 2023 18:24:45 UTC

This is how you generate a search key:

Photo of Rubai
Rubai
Fri, 28 Jul 2023 18:26:23 UTC

I am creating key with this curl `curl '' -X POST -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \` `-H 'Content-Type: application/json' \` `-d '{"description":"Search-only companies key.","actions": ["documents:search"], "collections": ["companies"]}'` but it won't for me , getting

Photo of Jason
Jason
Fri, 28 Jul 2023 18:27:22 UTC

That sounds like a networking problem. The browser is unable to connect to the Typesense server. It’s unrelated to api keys

Photo of Rubai
Rubai
Fri, 28 Jul 2023 18:28:33 UTC

Now I am getting

Photo of Jason
Jason
Fri, 28 Jul 2023 18:30:40 UTC

In your first screenshot I saw a different collection name. If that’s the collection you’re trying to search, you want to generate an API key with that collection name. The last code snippet you shared above has the collection name as “companies”, which is why it’s not working

Photo of Rubai
Rubai
Fri, 28 Jul 2023 18:31:34 UTC

no the curl was just demo . I updated the curl with our requirements

Photo of Rubai
Rubai
Fri, 28 Jul 2023 18:32:07 UTC

the 1st image of the thread is the collection name

Photo of Jason
Jason
Fri, 28 Jul 2023 18:45:06 UTC

To isolate the issue, could you give me a set of steps like this that reproduces the issue: That spins up an empty Typesense server, makes an api call to create a key and then uses that key to do a search?

Photo of Rubai
Rubai
Fri, 28 Jul 2023 19:32:19 UTC

what does the error means you can check the health for typesense here

Photo of Jason
Jason
Fri, 28 Jul 2023 19:49:10 UTC

If you look at the response body in the network tab in the browser tab, you’ll see the cause of the 404. If it just says not found, it’s likely the collection name is not found

Photo of Rubai
Rubai
Fri, 28 Jul 2023 19:53:06 UTC

can You please check here what's the issue

Photo of Rubai
Rubai
Fri, 28 Jul 2023 19:53:36 UTC

I can see the collection from collection API

Photo of Rubai
Rubai
Fri, 28 Jul 2023 19:54:00 UTC

Photo of Rubai
Rubai
Fri, 28 Jul 2023 21:22:28 UTC

is typesense host support in the / format ? my typesense host is `''`

Photo of Jason
Jason
Fri, 28 Jul 2023 21:26:22 UTC

You want to use the `path` config like this: ```{ host: "", port: "443", protocol: "https", path: '/typesense' }```

Photo of Rubai
Rubai
Fri, 28 Jul 2023 21:29:47 UTC

my typesense host in `'` and I am using like ```typesenseServerConfig: { nodes: [ { host: '', port: 443, protocol: https } ], apiKey: searchOnlyApiKey },```

Photo of Rubai
Rubai
Fri, 28 Jul 2023 21:31:14 UTC

beacuse i have the collection whatever we search . but can't able to call from frontend JS . is the cause for my host like `'` . is that then how I am call from frontend for this host

Photo of Jason
Jason
Fri, 28 Jul 2023 21:32:46 UTC

host has to be just the hostname “

Photo of Jason
Jason
Fri, 28 Jul 2023 21:33:12 UTC

```typesenseServerConfig: { nodes: [ { host: '', port: 443, protocol: 'https', path: '/typesense' } ], apiKey: searchOnlyApiKey },```

Photo of Rubai
Rubai
Fri, 28 Jul 2023 21:33:24 UTC

ok let me try

Photo of Rubai
Rubai
Fri, 28 Jul 2023 21:34:02 UTC

if path is empty then can it be cause any issue

Photo of Jason
Jason
Fri, 28 Jul 2023 21:34:20 UTC

Path is optional

Photo of Rubai
Rubai
Fri, 28 Jul 2023 21:34:37 UTC

ok

Photo of Rubai
Rubai
Fri, 28 Jul 2023 21:49:37 UTC

hey Jason thank you so much it's working now