2

我在一个带有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 运行正常。

4

3 回答 3

3

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

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

授权令牌与以下内容一起提供:

echo -n "user:password" | base64

于 2017-04-08T23:01:42.940 回答
0

你的配置是什么样的?可能是 HTTP 身份验证搞砸了。文档建议使用这样的东西:

# app/config/config.yml
fos_elastica:
    clients:
        default:
            host: your-bonsai-cluster.some-region.bonsai.io
            port: 443
            username: 'a1b2c3d4'
            password: 'e5f6g7h8'
于 2017-04-04T22:10:24.580 回答
0

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

于 2019-07-16T15:45:51.990 回答