elasticsearch-php get 的时候报错
来源:8-9 easyswoole结合elasticsearch初探
weixim
2019-07-02
$host=['127.0.0.1:9200'];
$client = ClientBuilder::create()->setHosts($host)->build();
$params = [
'index' => 'name',
'type' => 'php',
'id' => '3',
];
$response = $client->get($params);
print_r($response);
$this->writeJson('200',$response,'请求成功!');
No alive nodes found in your cluster
#0 /opt/htdocs/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Transport.php(77): Elasticsearch\ConnectionPool\StaticNoPingConnectionPool->nextConnection()
#1 /opt/htdocs/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Transport.php(94): Elasticsearch\Transport->getConnection()
#2 /opt/htdocs/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php(268): Elasticsearch\Transport->performRequest(‘GET’, ‘/name/php/3’, Array, NULL, Array)
#3 /opt/htdocs/vendor/react/promise/src/FulfilledPromise.php(25): Elasticsearch\Connections\Connection->Elasticsearch\Connections{closure}(Array)
#4 /opt/htdocs/vendor/guzzlehttp/ringphp/src/Future/CompletedFutureValue.php(55): React\Promise\FulfilledPromise->then(Object(Closure), NULL, NULL)
#5 /opt/htdocs/vendor/guzzlehttp/ringphp/src/Core.php(341): GuzzleHttp\Ring\Future\CompletedFutureValue->then(Object(Closure), NULL, NULL)
#6 /opt/htdocs/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php(310): GuzzleHttp\Ring\Core::proxy(Object(GuzzleHttp\Ring\Future\CompletedFutureArray), Object(Closure))
#7 /opt/htdocs/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php(211): Elasticsearch\Connections\Connection->Elasticsearch\Connections{closure}(Array, Object(Elasticsearch\Connections\Connection), Object(Elasticsearch\Transport), Array)
#8 /opt/htdocs/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Transport.php(104): Elasticsearch\Connections\Connection->performRequest(‘GET’, ‘/name/php/3’, Array, NULL, Array, Object(Elasticsearch\Transport))
#9 /opt/htdocs/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Client.php(1562): Elasticsearch\Transport->performRequest(‘GET’, ‘/name/php/3’, Array, NULL, Array)
#10 /opt/htdocs/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Client.php(241): Elasticsearch\Client->performRequest(Object(Elasticsearch\Endpoints\Get))
#11 /opt/htdocs/App/HttpController/Index.php(59): Elasticsearch\Client->get(Array)
#12 /opt/htdocs/vendor/easyswoole/http/src/AbstractInterface/Controller.php(98): App\HttpController\Index->search()
#13 /opt/htdocs/vendor/easyswoole/http/src/Dispatcher.php(182): EasySwoole\Http\AbstractInterface\Controller->__hook(‘search’, Object(EasySwoole\Http\Request), Object(EasySwoole\Http\Response))
#14 /opt/htdocs/vendor/easyswoole/http/src/Dispatcher.php(137): EasySwoole\Http\Dispatcher->controllerHandler(Object(EasySwoole\Http\Request), Object(EasySwoole\Http\Response), ‘/index/search’)
#15 /opt/htdocs/vendor/easyswoole/easyswoole/src/Core.php(255): EasySwoole\Http\Dispatcher->dispatch(Object(EasySwoole\Http\Request), Object(EasySwoole\Http\Response))
#16 {main}
1回答
-
weixim
提问者
2019-07-02
此问题已经解决了,连接问题,
在vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php
239行打印错误信息发现:
string(74) "cURL error 7: Failed to connect to 127.0.0.1 port 9200: Connection refused"
由于我是用的docker 运行的,curl链接的时候必须要用docker 的ip地址。
改成以后,解决
00
相似问题