#community-help

Troubleshooting Typesense Connection Issue and Data Retrieval

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

Powered by Struct AI
Jan 04, 2022 (24 months ago)
Felix
Photo of md5-5aa0910be941cf587b8f06d02839cf5c
Felix
06:38 AM
Hello Team
I need your help related to typesense connection.
I have created typesense on the server and tried to create collection from my local system with config of the server, but getting error. I have shared screenshot as well. So, anyone please help me out on this.
Thanks
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
06:39 AM
Are you connecting to localhost?
06:40
Kishore Nallan
06:40 AM
If you are using SSL certs for another domain but running your localhost server with that, you will run into SSL cert errors.
Felix
Photo of md5-5aa0910be941cf587b8f06d02839cf5c
Felix
06:41 AM
No i have tried with domain. But in error showing localhost. So i haven’t get proper idea about this.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
06:42 AM
Can you post the full command you used to start Typesense?
06:42
Kishore Nallan
06:42 AM
Also, how you have initialized the client?
Felix
Photo of md5-5aa0910be941cf587b8f06d02839cf5c
Felix
06:42 AM
yes
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
06:42 AM
It seems like your client is connecting to localhost, because it is showing localhost:8108
Felix
Photo of md5-5aa0910be941cf587b8f06d02839cf5c
Felix
06:43 AM
this is my code
06:43
Felix
06:43 AM
06:44
Felix
06:44 AM
06:44
Felix
06:44 AM
I am creating collection using above code.
06:44
Felix
06:44 AM
Please take a look and give me your thought please.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
06:45 AM
Can you try printing $this->client just before the create() call?
06:45
Kishore Nallan
06:45 AM
Just to ensure that the client object is indeed correct.
Felix
Photo of md5-5aa0910be941cf587b8f06d02839cf5c
Felix
06:48 AM
I have printed $this->client and getting this. Please take a look once.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
06:49 AM
Hmm, that looks okay to me and <http://search2.thebestrealestatesearch.com:8108/health> is showing healthy.
06:51
Kishore Nallan
06:51 AM
Can you check /etc/hosts ? Whether you have some mapping that resolves that domain to localhost on your local machine?
Felix
Photo of md5-5aa0910be941cf587b8f06d02839cf5c
Felix
06:52 AM
you mean my local system /etc/hosts ?
06:52
Felix
06:52 AM
or server ?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
06:52 AM
Yes
Felix
Photo of md5-5aa0910be941cf587b8f06d02839cf5c
Felix
06:53 AM
okay
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
06:53 AM
On your local
06:54
Kishore Nallan
06:54 AM
Also, can you try running this standalone example from the Typesense PHP client? https://github.com/typesense/typesense-php/blob/master/examples/collection_operations.php
Felix
Photo of md5-5aa0910be941cf587b8f06d02839cf5c
Felix
06:54 AM
this is my local system hosts file
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
06:55 AM
Okay that looks fine, you can delete the screenshot.
06:55
Felix
06:55 AM
and get back to you again.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
06:55 AM
👍
Felix
Photo of md5-5aa0910be941cf587b8f06d02839cf5c
Felix
07:33 AM
Same issue 😞
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
07:34 AM
Okay, can we try with curl from the CLI?
07:34
Kishore Nallan
07:34 AM
Check the shell tab in the examples in the docs. Try doing a shell curl.
07:35
Kishore Nallan
07:35 AM
Somehow the client is not connecting to the remote host, but to localhost. There are several projects using the PHP client, so I don't know what is going wrong here. Let's see if raw curl works.
Felix
Photo of md5-5aa0910be941cf587b8f06d02839cf5c
Felix
08:21 AM
I have tried with curl as well. But getting same error. Let me send you screenshot.
08:23
Felix
08:23 AM
getting this
08:23
Felix
08:23 AM
Code is here
08:23
Felix
08:23 AM
$booksSchema = array();
        $booksSchema['name'] = 'property_residentials';
        $booksSchema['fields'] = array();
        $t = array();
        $t['name'] = 'property_id';
        $t['type'] = 'int32';
        array_push($booksSchema['fields'], $t);
        $t = array();
        $t['name'] = 'AcresTotal';
        $t['type'] = 'float';
        array_push($booksSchema['fields'], $t);
        $booksSchema['default_sorting_field'] = 'property_id';
        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, '');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($booksSchema));

        $headers = array();
        $headers[] = 'Content-Type: application/json';
        $headers[] = 'X-Typesense-Api-Key: APIKEY';

        // $headers[] = 'X-Typesense-Api-Key: nXSIQvLOVAc9mg1wYKL9SSdOHzYulqTCcnauUEIdulqt5nSt';
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

        $result = curl_exec($ch);
        if (curl_errno($ch)) {
            echo 'Error:' . curl_error($ch);
        }
        curl_close($ch);
        dd($result);
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:24 AM
I meant using the commandline curl command. Check the shell tab in the examples, like here: https://typesense.org/docs/0.22.1/api/collections.html#with-pre-defined-schema
08:25
Kishore Nallan
08:25 AM
Also, the URL is wrong, it should be /collections and not /collection
08:25
Kishore Nallan
08:25 AM
That's why you are seeing a "not found" message. Just change that, and it should work.
08:26
Kishore Nallan
08:26 AM
Change:

curl_setopt($ch, CURLOPT_URL, '');

to:

curl_setopt($ch, CURLOPT_URL, '');
08:26
Kishore Nallan
08:26 AM
Also, the // $headers[] should not be commented out.
Felix
Photo of md5-5aa0910be941cf587b8f06d02839cf5c
Felix
08:28 AM
Okay let me check . Get back to you quick.
08:46
Felix
08:46 AM
Thank you for your support. Give me your thought for 3rd number issue.
Resolved the issue with curl
1. create collection done
2. insert data in collection done
3. getting issue with get collection data (Please help me out on this)
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:47 AM
If curl works then certainly the earlier issue is with some client misconfiguration.Are you using the scout extension or just the php client?
Felix
Photo of md5-5aa0910be941cf587b8f06d02839cf5c
Felix
08:48 AM
php client
08:48
Felix
08:48 AM
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, '');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'X-Typesense-Api-Key: APIKEY';


$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
dd($result);
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:48 AM
Can you post a gist with a minimally reproduceable example that fails, I can get someone to take a look.
Felix
Photo of md5-5aa0910be941cf587b8f06d02839cf5c
Felix
08:48 AM
I am using above code for get collection data.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:54 AM
You mean searching?
Felix
Photo of md5-5aa0910be941cf587b8f06d02839cf5c
Felix
08:55 AM
Yes, I want to get my data from collection.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:56 AM
You've to use /collections/name/documents/search endpoint for that.
08:56
Kishore Nallan
08:56 AM
Felix
Photo of md5-5aa0910be941cf587b8f06d02839cf5c
Felix
09:02 AM
Okay thanks let me check once.
10:02
Felix
10:02 AM
Well, Everything working fine now.
Thanks Kishore :thumbsup:
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
10:03 AM
Welcome. Though, I wonder why the official client is not working. Is it possible for you share a stand-alone php file that showcases the issue? The client is somehow not picking the right host while making the call.
Felix
Photo of md5-5aa0910be941cf587b8f06d02839cf5c
Felix
10:06 AM
Yes, that’s fine.
let me share you my code.
10:11
Felix
10:11 AM
This is my file. Please take a look once from your end. If you will get any success then please let me know as well. Thanks 😊
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
10:12 AM
👍
Felix
Photo of md5-5aa0910be941cf587b8f06d02839cf5c
Felix
02:19 PM
Hello Friend,
I need your help related to typsense port and ssl stuff.
02:19
Felix
02:19 PM
So are you available now ?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
05:31 PM
Felix In your original client initialization code here (https://typesense-community.slack.com/archives/C01P749MET0/p1641278619386400?thread_ts=1641278328.384600&amp;cid=C01P749MET0) you want to remove "http://" from the hostname. It should just be search2.thebestrealestatesearch.com
05:32
Jason
05:32 PM
Feel free to post follow up questions here about SSL / Ports, etc

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

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.

1

30
4mo

Troubleshooting Issues with DocSearch Hits and Scraper Configuration

Rubai encountered issues with search result priorities and ellipsis. Jason helped debug the issue and suggested using different versions of typesense-docsearch.js, updating initialization parameters, and running the scraper on a Linux-based environment. The issues related to hits structure and scraper configuration were resolved.

7

131
8mo

Troubleshooting Typesense Docsearch Scraper Setup Issue

Vinicius experienced issues setting up typesense-docsearch-scraper locally. Jason identified a misconfiguration with the Typesense server after checking the .env file, and recommended using ngrok or port forwarding for development purposes. Vinicius successfully resolved the issue with port forwarding.

2

12
5mo

Issues with Importing Typesense Collection to Different Server

Kevin had problems migrating a Typesense collection between Docusaurus sites on different machines. Jason advised them on JSONL format, handling server hosting, and creating a collection schema before importing documents, leading to successful import.

3

35
3mo

Resolving Typesense Analytics "top_queries" Collection Issue

Zain faced issues with typesense analytics and an empty "top_queries" collection. Jason and Kishore Nallan assisted in troubleshooting, identified a bug, and suggested a fix in `0.25.0.rc66`. The fix worked for Zain.

3

29
4mo