带集群的 Elastica 客户端

Elastica Client with cluster

我有一个带 Compose.io 的 Elasticsearch 集群,但我无法连接到 Elastica 客户端。这是我的配置:

    $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');

我遇到了这个错误:

无法解析主机 500 内部服务器错误

如何正确连接数据库?

要测试您的问题是否与 Elastica 相关,或者访问服务是否存在问题(我假设),请使用 curl:

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

如果服务器 "works" 符合预期,您将获得带有 elasticserach 服务器状态的 JSON 结果。在这种情况下,问题与 Elastica 相关。在所有其他情况下,我假设问题在某种程度上与防火墙设置、证书问题或其他服务器问题有关,而不是 Elastica 特定的。

另请注意,在 Elastica 中使用 'servers' 数组已被弃用。应该使用具有相同参数的服务器 'connections' 而不是服务器。

必须在没有协议的情况下指定参数 host

如果您想使用 https,您应该将 transport 参数设置为 Https(而不是默认使用的 Http)。

$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');