Connect to Elasticsearch service with Elasticsearch-php

I looked in several topics without finding solutions, so I put my problem directly there.

i want to communicate with my trial account on Elastic Cloud using the Google Cloud Platform with a PHP scirpt :

require_once 'vendor/autoload.php';

use Elasticsearch\ClientBuilder;

$hosts = [
        'host' => '',
        'user' => 'username',
        'pass' => 'password'

$client = ClientBuilder::create()           // Instantiate a new ClientBuilder
                    #->setHosts($hosts)      // Set the hosts

$params = [
    'index' => 'tests',
    'type' => 'test',
    'id' => '01',
    'body' => ['testField' => 'abc']

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


But it doesn't work, i have :
fatal error : Uncaught Elasticsearch\Common\Exceptions\NoNodesAvailableException: No alive nodes found in your cluster in D:\Documents\ElasticSearch\test\vendor\elasticsearch\elasticsearch\src\Elasticsearch\ConnectionPool\StaticNoPingConnectionPool.php:51
Stack trace:
#0 D:\Documents\ElasticSearch\test\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Transport.php(72): Elasticsearch\ConnectionPool\StaticNoPingConnectionPool->nextConnection()
#1 D:\Documents\ElasticSearch\test\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Transport.php(90): Elasticsearch\Transport->getConnection()
#2 D:\Documents\ElasticSearch\test\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Connections\Connection.php(240): Elasticsearch\Transport->performRequest('PUT', '/tests/test/01', Array, '{"testField":"a...', Array)
#3 D:\Documents\ElasticSearch\test\vendor\react\promise\src\FulfilledPromise.php(25): Elasticsearch\Connections\Connection->Elasticsearch\Connections{closure}(Array)
#4 D:\Documents\ElasticSearch\test\vendor\guzzlehtt in D:\Documents\ElasticSearch\test\vendor\elasticsearch\elasticsearch\src\Elasticsearch\ConnectionPool\StaticNoPingConnectionPool.php on line 51

I also tried with defaultHosts "localhost:9200" and it work.

Do anyone have any idea of how to make this work with google cloud host?

Update :

When i set in composer.json : "elasticsearch/elasticsearch": "~1.0", it work on windows.

In that case, i create a new Client like this :

$client = new Elasticsearch\Client([
	'hosts' => ['']

But i want to run my php script on ubuntu, and i can't install composer with this config.

It's really strange that it don't work with 6.7 version of elasticsearch.

Did i misunderstand something?

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