我在一个带有FOSElasticaBundle的 Symfony 项目中使用 elasticsearch ,这需要ruflin/elastica客户端。为了创建索引,我使用了FOSElasticaBundle文档中建议的命令,在我的本地机器上一切正常。
当我将项目部署到 heroku 时,相同的命令失败并引发以下错误:
elastica.ERROR: Elastica Request Failure {"exception":"[object] (Elastica\\Exception\\Connection\\HttpException(code: 0): Couldn't resolve host at /app/vendor/ruflin/elastica/lib/Elastica/Transport/Http.php:186)","request":{"path":"index_name/","method":"DELETE","data":[],"query":[],"connection":{"config":{"headers":[],"curl":[]},"host":"https://username:password@host","port":"443","logger":"fos_elastica.logger","compression":false,"retryOnConflict":0,"enabled":false}},"retry":false}
这似乎强调了弹性搜索主机的连接问题。奇怪的是,当我尝试从 heroku 机器手动连接到该主机时,一切似乎都运行良好。
执行:
curl -X GET host:port/
给我这个回应:
{
"name" : "Alex Power",
"cluster_name" : "elasticsearch",
"version" : {
"number" : "2.4.0",
"build_hash" : "079e104a99267f24d3689297eb16466170b00ebc",
"build_timestamp" : "2016-10-04T20:50:33Z",
"build_snapshot" : false,
"lucene_version" : "5.5.2"
},
"tagline" : "You Know, for Search"
}
在 heroku 上,我使用的是bonsai add-on,但我也尝试使用 AWS elasticsearch 服务,以及使用不同版本的捆绑包和 ruflin/elastica 客户端的所有内容。
恢复问题:主机始终工作正常,但 ruflin 客户端似乎无法与它联系。
我唯一能想到的是捆绑包的错误配置,但我遵循了文档中的每一步,所以我不知道在哪里看,此刻我感到迷茫。
编辑:我只是将项目设置为在本地的 docker 容器中运行,在日志中我看到以下错误:
[2017-04-08 09:45:00] request.CRITICAL: Uncaught PHP Exception Elastica\Exception\Connection\HttpException: "Couldn't connect to host, Elasticsearch down?" at /var/www/vendor/ruflin/elastica/lib/Elastica/Transport/Http.php line 180 {"exception":"[object] (Elastica\\Exception\\Connection\\HttpException(code: 0): Couldn't connect to host, Elasticsearch down? at /var/www/vendor/ruflin/elastica/lib/Elastica/Transport/Http.php:180)"} []
我一直在想这只是一个配置问题,因为我检查了 curl 并且 elasticsearch 运行正常。