When attempting to use the PHP client and to specify the ES host and port via the Extended Host Configuration notation, a connection exception is thrown. It may be that perhaps the documented example is not complete?
For example, the following code snippet results in the exception that follows:
$hosts = [
'host' => 'localhost',
'port' => '9200',
'scheme' => 'http',
'user' => 'elastic',
'pass' => 'changeme'
];
However, specifying the host and port in the following way against the same instance works successfully:
$hosts = [
'http://elastic:changeme@localhost:9200',
];
Results:
Array ( [_index] => products [_type] => product [_id] => 2 [_version] => 1 [found] => 1 [_source] => Array ( [brandName] => Caress [customerRating] => 5 [price] => 3 [grp_id] => 2 [quantitySold] => 760139 [upc12] => 011111065925 [productName] => Caress Velvet Bliss Ultra Silkening Beauty Bar - 6 Ct ) )
Attached is a zip of the test case Apache site, where PHP pages showing the full code for working (testWorking.php) and non-working (test NotWorking.php) examples. This was reported in the field and reproduced locally on an Apache Httpd instance running against ES + XPack (no SSL) in the following config:
The extended syntax is an array of maps, while your's is just a single map. It should look like:
$hosts = [
[ // <----------------- here
'host' => 'localhost',
'port' => '9200',
'scheme' => 'http',
'user' => 'elastic',
'pass' => 'changeme'
] // <----------------- and here
];
We could probably add some better validation though, so that it only accepts an array of strings (simple syntax) or array of maps (extended syntax), otherwise throw an exception so the user knows it is bad config rather than something else.
Ah, thanks for pointing out the mistake. I and the person who originally alerted me to this mis-read the example.
I agree, though it is demonstrated in the example, perhaps it could be made clearer like you mentioned.
Thanks,
Alex
Happy to help! :)
I'll try to work up some validation code this week. Will leave this ticket open as a reminder.
Thank so much!
Outdated issue
Most helpful comment
The extended syntax is an array of maps, while your's is just a single map. It should look like:
We could probably add some better validation though, so that it only accepts an array of strings (simple syntax) or array of maps (extended syntax), otherwise throw an exception so the user knows it is bad config rather than something else.