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.
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