PHP Connection issue with elasticsearch-PHP client, CURL working fine

I've been struggling with this for a few days. I initially posted this question on the Elastic Cloud, but they advised to post here.

I have a PHP app running in a Slim2 framework, with Elastic as a
local installation all working no problems. Elastic PHP client v2 etc
all configured fine. I'm using a config file to pass connection
parameters to the Elastic PHP client

Basically I connect to the local cluster with a 'host' = ''
and set an index with
'es_index' => [ 'index' => 'test_index' ]

This all works fine.

So I setup an Elastic Cloud cluster to trial a production level
capability. Did that no problem, configured Shield etc, all working.

I can connect to this cluster direct from the server(s) with a simple:

curl -XGET ''

user, password and cluster name not real in above line, but you get the idea.

That seems to work fine, but if I replace the path in the PHP config file with this endpoint

'path' => ''

I get nothing, it essentially cannot find the cluster, even though a cluster and index are present.

So I know I am making a very basic error, but I just can find any
help, or a decent example. I've tried this from a vagrant box, CURL
works, PHP doesn't. I've tried it from a Server, same problem.

Can someone point me at some help or an example? I can't see why I
can connect from any of these servers via CURL, but the path in the
config file bombs, when it works fine with a local path. I'm assuming
there is a config issue somewhere that I'm missing?

Thanks Guys

Not sure if this might help, but if I print_r the $response, I get this with the full end point

Array ( [ok] => [message] => Unknown cluster.)

If I shorten the end point to -

then $response returns

Array ( [error] => IndexMissingException[[soros_test] missing] [status] => 404)

So I'm not sure if this is saying the cluster is now found, but the index is unavailable?

Of course if I cut and paste the full endpoint into the browser I get
the expected response, so I'm assuming this is a configuration issue
somewhere in elasticsearch-PHP.

Even tried turning on inline scripting but that had no effect.

Completely lost as to what to try next?

The cloud guys have suggested this is probably an issue between the elasticsearch-PHP libs and the Slim2 framework. I'm guessing this is something about the way the URL is being interpreted?

Hi @airper,

let me set a few expectations: I know basically nothing about PHP and the Slim2 framework. So I can just give you a couple of generic pointers but I hope this helps you to solve your problem anyway.

I just looked up Slim2 and to me it looks like it cannot really interfere that much with your Elasticsearch configuration. However, can you try to dump down your script to the bare essentials and just get it connect to the cluster?

According to the PHP client docs, try to do something along the lines of:

$hosts = [
$clientBuilder = ClientBuilder::create();
$client = $clientBuilder->build();

// get cluster stats - if the connection is fine, this will work even if you did not create an index
$response = $client->cluster()->stats();

If that works, it shows that the PHP client can connect fine and you can iterate from there.

A couple of other suggestions and comments:

  • In the beginning you say "I connect to the local cluster with a 'host' = ''" but then you also say "'path' => ''". Did you mix up the config parameters and this should actually say host instead of path?
  • You should use HTTPS to encrypt the traffic (HTTPS port is 9243 on Elastic Cloud)
  • Inline scripting allows you to use scripts in your queries (see docs). So it is not related to your problem and you can turn it off again.

I hope these hints get you on the right track.


Thanks Daniel, but I think this is an issue with the way the framework renders the URL. Slim is a MVC framework, I think it cannot render the URL structure, which is why this is working with a more basic local URL and not with the remote URL needed by Elastic Cloud.

I'm not sure this is fixable, without development of the framework itself.

I'd be interested to know if Laravel has similar issues with Elastic Cloud?

Hi, just had a similar issue with Elasticsearch-PHP client and an AWS Elasticsearch cluster.

Endpoint was :
(This one is fake but similar)

Trying this failed:

$client = ClientBuilder::create()->setHosts([

But this is working:

$client = ClientBuilder::create()->setHosts([

Hope it can help a future-me!