yes, it works with IP. But it works on a remote machine, not local.
But when I run it on a remote machine it works fine.
this code is on the remote machine (this machine IP address 10.21.8.164)
<? php
ini_set ('display_errors', 1);
ini_set ('display_startup_errors', 1);
error_reporting (E_ALL);
require 'vendor / autoload.php';
use Elasticsearch \ ClientBuilder;
$ hosts = [
'10 .21.8.146: 9200 '// IP + Port
];
$ client = ClientBuilder :: create () -> setHosts ($ hosts) -> build ();
$ indices = $ client-> cat () -> indices (array ('index' => '*'));
var_dump ($ indices);
print_r ($ indices [0]);
If this code is running in local (this machine address 10.21.8.146)
<? php
ini_set ('display_errors', 1);
ini_set ('display_startup_errors', 1);
error_reporting (E_ALL);
require 'vendor / autoload.php';
use Elasticsearch \ ClientBuilder;
$ hosts = [
'localhost: 9200' // IP + Port
];
$ client = ClientBuilder :: create () -> setHosts ($ hosts) -> build ();
$ indices = $ client-> cat () -> indices (array ('index' => '*'));
var_dump ($ indices);
print_r ($ indices [0]);
The error returns when running in local is as follows.
** Fatal error **: Uncaught Elasticsearch \ Common \ Exceptions \ NoNodesAvailableException: No alive nodes found in your cluster in /var/www/vendor/elasticsearch/elasticsearch/src/Elasticsearch/ConnectionPool/StaticNoPingConnectionPool.php:51 Stack trace: # 0 /var/www/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Transport.php(72): Elasticsearch \ ConnectionPool \ StaticNoPingConnectionPool-> nextConnection () # 1 / var / www / vendor / elasticsearch / elasticsearch / src / Elasticsearch /Transport.php(90): Elasticsearch \ Transport-> getConnection () # 2 /var/www/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php(256): Elasticsearch \ Transport-> performRequest (' GET ',' / _cat / indices /% ... ', Array, NULL, Array) # 3 /var/www/vendor/react/promise/src/FulfilledPromise.php(28): Elasticsearch \ Connections \ Connection-> Elasticsearch \ Connections \ {closure} (Array) # 4 /var/www/vendor/guzzlehttp/ringphp/src/Future/CompletedFutureValue.php(55): React \ Promise \ FulfilledPromise-> then (Object (Closure), NU LL, NULL) # 5 / var / www / vendor / guzzlehttp / rin in ** / var / www / vendor / elasticsearch / elasticsearch / src / Elasticsearch / ConnectionPool / StaticNoPingConnectionPool.php ** on line ** 51 **
This is working remote machine
This is local machine

