使用 ruflin/elastica 重置索引会在 heroku 上抛出 HttpException



我在带有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 上,我正在使用盆景附加组件,但我也尝试了使用 AWS elasticsearch 服务,以及不同版本的捆绑包和 ruflin/elastica 客户端的所有内容。

恢复问题:主机始终工作正常,但 ruflin 客户端似乎在联系它时遇到问题。

我唯一能想到的是捆绑包的错误配置,但我遵循了文档中的每一步,所以我不知道该去哪里看,此刻我感到迷茫。

编辑: 我只是将项目设置为在本地 docker 容器中运行,并且在日志中看到以下错误:

[2017-04-08 09:45:00] request.CRITICAL: Uncaught PHP Exception ElasticaExceptionConnectionHttpException: "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 是否正常运行。

我使用以下配置解决了这个问题:

clients: default: host: **** port: **** transport: Https headers: Authorization: "Basic ************"

授权令牌的提供方式为:

echo -n "user:password" | base64

您的配置是什么样的?可能是HTTP身份验证弄乱了事情。文档建议使用类似的东西:

# app/config/config.yml
fos_elastica:
clients:
default:
host: your-bonsai-cluster.some-region.bonsai.io
port: 443
username: 'a1b2c3d4'
password: 'e5f6g7h8'

Bonsai 还支持通过端口 9200 和端口 80 进行连接。 使用端口 80 以避免 SSL 错误。

最新更新