New

The executive guide to generative AI

Read more

Example: Configuring the Hosts

edit
IMPORTANT: This documentation is no longer updated. Refer to Elastic's version policy and the latest documentation.

Example: Configuring the Hosts

edit

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):

$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
);

$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.

Was this helpful?
Feedback