我是elasticSearch的新手,请帮帮我。我在php
<?php
require '../../vendor/autoload.php';
$params = array();
$params['hosts'] = array (
'https://localhost', // SSL to localhost
);
$params['connectionParams']['auth'] = array(
'root',
'',
'Basic'
);
$params1 = array(
'index' => 'test_missing',
'type' => 'test',
'id' => 1,
'ignore' => 404
);
$client = new Elasticsearch\Client($params);
echo $client->get($params1);
但是我遇到致命错误
Fatal error: Uncaught exception 'Elasticsearch\Common\Exceptions\Curl\CouldNotConnectToHost' with message 'Failed connect to localhost:9200; No error' in
C:\xampp\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Connections\AbstractConnection.php:308 Stack trace: #0
C:\xampp\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Connections\GuzzleConnection.php(307): Elasticsearch\Connections\AbstractConnection->throwCurlException(7, 'Failed connect ...') #1
C:\xampp\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Connections\GuzzleConnection.php(197): Elasticsearch\Connections\GuzzleConnection->processCurlError(Object(Guzzle\Http\Exception\CurlException)) #2
C:\xampp\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Connections\GuzzleConnection.php(104): Elasticsearch\Connections\GuzzleConnection->sendRequest(Object(Guzzle\Http\Message\Request), NULL) #3
C:\xampp\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Transport.php(166): Elasticsearch\Connections\GuzzleConnection->performRequest('GET', '/test_miss in C:\xampp\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Connections\AbstractConnection.php on line 308
我在Windows 7中使用xampp for php 提前谢谢。
答案 0 :(得分:0)
虽然我没有使用https,所以我不是100%确定这些连接的格式,我这里的代码没有在hosts数组中指定协议(我有一个不同的端口号,所以将它附加到主机,它看起来像是可选的,但无论如何我都把它包括在内):
$ params [&#39; hosts&#39;] = array(&#39; localhost:9200&#39;);
除此之外,其余的看起来还不错。
这个问题也许有帮助: using https with elasticsearch-php client