2

I have an Elasticsearch cluster with Compose.io but I can't connect with Elastica Client. This is my configuration :

    $elasticaClient = new \Elastica\Client(array(
        'servers' => array(
            array('host' => 'https://myusername:mypass@aws-us-east-1-portal2.dblayer.com', 'port' => 10050),
            array('host' => 'https://myusername:mypass@aws-us-east-1-portal3.dblayer.com', 'port' => 10062)
        )
    ));
    $elasticaIndex = $elasticaClient->getIndex('test');

I got this error :

Couldn't resolve host 500 Internal Server Error

How to correctly connect to the database ?

Siol
  • 311
  • 8
  • 21

2 Answers2

5

Parameter host must be specified without protocol.

If you want to use https, you should set transport parameter to Https (instead of Http which used by default).

$elasticaClient = new \Elastica\Client([
    'connections' => [
        ['transport' => 'Https', 'host' => 'myusername:mypass@aws-us-east-1-portal2.dblayer.com', 'port' => 10050],
        ['transport' => 'Https', 'host' => 'myusername:mypass@aws-us-east-1-portal3.dblayer.com', 'port' => 10062],
    ],
]);
$elasticaIndex = $elasticaClient->getIndex('test');
Igor Denisenko
  • 254
  • 2
  • 7
  • That's working, this is the complete answer code from Igor : $elasticaClient = new \Elastica\Client([ 'connections' => [ [ 'transport' => 'Https', 'host' => 'user:****@aws-us-east-1-portal3.dblayer.com', 'port' => 10050, 'curl' => [ CURLOPT_SSL_VERIFYPEER => false, ], ], ], ]); – Siol May 30 '15 at 17:50
3

To test if your issue is Elastica related or if there is an issue with the access to the service (which I assume), use curl:

curl https://myusername:mypass@aws-us-east-1-portal2.dblayer.com:10050

If the server "works" as expected you will get a JSON result with the elasticserach server status. In this case the problem is Elastica related. In all the other cases I assume the problem is somehow related to the firewall settings, issues with the certificate or other server issues and is not Elastica specific.

Please also be aware that using 'servers' array in Elastica is deprecated. Instead of servers 'connections' with the same parameters should be used.

ruflin
  • 206
  • 1
  • 3
  • The curl working on local and prod, I can see JSON answer but I can't find out what is wrong with Elastica. – Siol May 29 '15 at 17:07