Can´t connect using https to Elastic Cloud on GCP with PHP

I´m trying for a few days to setup a "Hello Word" with my trial account on Elastic Cloud using the Google Cloud Platform.

I had set up the cloud servers and I can connect them directly with the browser on endpoint:https://7fea4de80333428485717a0da463ce05.us-central1.gcp.cloud.es.io:9243/

When trying to connect to it with ElasticSearch PHP API, I get the following error: Fatal error: Uncaught Elasticsearch\Common\Exceptions\NoNodesAvailableException: No alive nodes found in your cluster in /home/mysite/public_html/mysite.com/vendor/elasticsearch/elasticsearch/src/Elasticsearch/ConnectionPool/StaticNoPingConnectionPool.php

I´m using a HostGator shared hosting with free SSL certificate to run the php script.

Here is the code:

    <?php
    require 'vendor/autoload.php';

    use Elasticsearch\ClientBuilder;

    $hosts = ["https://elastic:mypassword@7fea4de80333428485717a0da463ce05.us-central1.gcp.cloud.es.io:9243/"];

    $client = ClientBuilder::create()
                        ->setHosts($hosts)
                        ->build();

    $params = [
        'index' => 'my_index',
        'type' => 'my_type',
        'id' => 'my_id',
        'body' => ['testField' => 'abc']
    ];

    $response = $client->index($params);

    echo $response;

    ?>

I also tried to install ElasticSearch on localhost. The same code works on localhost if I use http instead of https, but Elastic Cloud on GCP do not support http (as far as I know).

Do anyone have ANY idea of how to make this simple work? I tried a few things like using the CaBundle as pointed in ElasticSearch docs, but no success with it.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.