2

I'm using elasticsearch in a Symfony project with FOSElasticaBundle, that requires ruflin/elastica client. In order to create indexes I use the command suggested in the documentation of FOSElasticaBundle and in my local machine everything is going fine.

When I deploy the project to heroku, the same command fails throwing the following error:

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} 

That seems to underline a connection problem with the elasticsearch host. The strange thing is that when I try to connect manually to that host from the heroku machine, everything seems to work just fine.

Executing:

curl -X GET host:port/

gives me this response:

{
    "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"
}

On heroku I'm using bonsai add-on, but I also tried with the AWS elasticsearch service, and everything with different version of the bundle and the ruflin/elastica client.

Resuming the problem: the host is always working fine, but the ruflin client seems to have problems contacting it.

The only thing I can think about is a misconfiguration of the bundle, but I followed every step in the documentation, so I don't know where to look and I'm feeling lost at this moment.

EDIT: I just setup the project to run in docker containers locally and in logs I see the following error:

[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)"} []

I keep thinking is just a configuration problem, because I checked with curl and elasticsearch is running properly.

rastafermo
  • 408
  • 1
  • 5
  • 13

3 Answers3

3

I solved this using the following configuration:

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

Where the authorization token is given with:

echo -n "user:password" | base64

rastafermo
  • 408
  • 1
  • 5
  • 13
0

What does your configuration look like? It could be that the HTTP authentication is messing with things. The docs suggest using something like this:

# app/config/config.yml
fos_elastica:
    clients:
        default:
            host: your-bonsai-cluster.some-region.bonsai.io
            port: 443
            username: 'a1b2c3d4'
            password: 'e5f6g7h8'
Rob Sears
  • 366
  • 1
  • 5
  • I'm using the following configuration: `fos_elastica: clients: default: { host: %elastic_host%, port: %elastic_port% }` where elastic host is something like scheme://username:password@elastichost.bonsai.io and the port is 443. I've just tried the solution you suggest and the result is `[Symfony\Component\Config\Definition\Exception\InvalidConfigurationException] remote: Unrecognized options "username, password" under "fos_elastica.clients.default.connections.0" `. – rastafermo Apr 04 '17 at 22:27
  • I also updated my version of FOSElasticaBundle in order to have those parameters as legal, but now I get an unknown error (at first I was having a 'Could not resolve host' error) – rastafermo Apr 04 '17 at 23:21
0

Bonsai also supports connecting via port 9200 and port 80. Use port 80 to avoid the SSL error.

Tac Tacelosky
  • 3,165
  • 3
  • 27
  • 28