【问题标题】:Resetting indexes with ruflin/elastica throws HttpException on heroku使用 ruflin/elastica 重置索引会在 heroku 上引发 HttpException
【发布时间】:2017-08-30 04:49:43
【问题描述】:

我在 FOSElasticaBundle 的 Symfony 项目中使用 elasticsearch,这需要 ruflin/elastica 客户端。为了创建索引,我使用了 FOSElasticaBundle 的 command suggested in the documentation,在我的本地机器上一切正常。

当我将项目部署到 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} 

这似乎强调了与 elasticsearch 主机的连接问题。奇怪的是,当我尝试从 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 运行正常。

【问题讨论】:

    标签: elasticsearch elastica foselasticabundle httpexception bonsai-elasticsearch


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

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

      授权令牌在哪里给出:

      echo -n "user:password" | base64

      【讨论】:

        【解决方案3】:

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

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

        【讨论】:

        • 我正在使用以下配置:fos_elastica: clients: default: { host: %elastic_host%, port: %elastic_port% } 其中弹性主机类似于 scheme://username:password@elastichost.bonsai.io 并且端口是 443。我刚刚尝试过你建议的解决方案,结果是[Symfony\Component\Config\Definition\Exception\InvalidConfigurationException] remote: Unrecognized options "username, password" under "fos_elastica.clients.default.connections.0"
        • 我还更新了我的 FOSElasticaBundle 版本以使这些参数合法,但现在我收到一个未知错误(起初我遇到“无法解析主机”错误)
        猜你喜欢
        • 2019-03-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-02-24
        相关资源
        最近更新 更多