请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

elasticsearch-php get 的时候报错

   $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}

正在回答 回答被采纳积分+3

1回答

提问者 weixim 2019-07-02 13:46:47

此问题已经解决了,连接问题,

在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地址。

改成以后,解决

//img1.sycdn.imooc.com//szimg/5d1aef5600019fb125981482.jpg

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号