Host Configurationedit

A common operation will be telling the client what nodes are in your cluster. By default, the client will connect to localhost:9200, which obviously doesn’t work in many production environments.

All configurations (both simple parameters and more advanced component-replacement) are injected into the constructor of the client.

The client accepts an array of hosts that you would like to connect to. Each value in the array must be a string (either with or without the port number). SSL can be enabled by prefixing the host with https:

$params = array();
$params['hosts'] = array (
    '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
    'http://user:pass@localhost:9200',  // HTTP Basic Auth
    'https://user:pass@localhost:9200',  // SSL + HTTP Basic Auth
);

$client = new Elasticsearch\Client($params);

This associative array holds all custom configurations that you may want to set. Often, you’ll only need to configure the hosts, but if you need more advanced behavior, read on.