$hosts = ['192.168.1.1:9200',// IP + Port'192.168.1.2',// Just IP'mydomain.server.com:9201',// Domain + Port'mydomain2.server.com',// Just Domain'https://localhost',// SSL to localhost'https://192.168.1.3:9200'// SSL to IP + Port];$client =ClientBuilder::create()// Instantiate a new ClientBuilder->setHosts($hosts)// Set the hosts->build(); // Build the client object
注意,ClientBuilder对象允许链式方法要求简洁。也可以单独调用的方法:
$hosts = ['192.168.1.1:9200',// IP + Port'192.168.1.2',// Just IP'mydomain.server.com:9201',// Domain + Port'mydomain2.server.com',// Just Domain'https://localhost',// SSL to localhost'https://192.168.1.3:9200'// SSL to IP + Port];$clientBuilder =ClientBuilder::create(); // Instantiate a new ClientBuilder$clientBuilder->setHosts($hosts); // Set the hosts$client = $clientBuilder->build(); // Build the client object
$hosts = [// This is effectively equal to: "https://username:password!#$?*abc@foo.com:9200/" ['host'=>'foo.com','port'=>'9200','scheme'=>'https','user'=>'username','pass'=>'password!#$?*abc' ],// This is equal to "http://localhost:9200/" ['host'=>'localhost',// Only host is required ]];$client =ClientBuilder::create()// Instantiate a new ClientBuilder->setHosts($hosts)// Set the hosts->build(); // Build the client object