- PHP Client: other versions:
- Overview
- Quickstart
- Installation
- Configuration
- Inline Host Configuration
- Extended Host Configuration
- Authorization and Encryption
- Set retries
- Enabling the Logger
- Configure the HTTP Handler
- Setting the Connection Pool
- Setting the Connection Selector
- Setting the Serializer
- Setting a custom ConnectionFactory
- Set the Endpoint closure
- Building the client from a configuration hash
- Per-request configuration
- Future Mode
- Dealing with JSON Arrays and Objects in PHP
- Index Management Operations
- Indexing Documents
- Getting Documents
- Updating Documents
- Deleting documents
- Search Operations
- Namespaces
- Security
- Connection Pool
- Selectors
- Serializers
- PHP Version Requirement
- Breaking changes from 5.x
- Community DSLs
- Community Integrations
- Reference - Endpoints
- Elasticsearch\Client
- Elasticsearch\ClientBuilder
- Elasticsearch\Namespaces\CatNamespace
- Elasticsearch\Namespaces\ClusterNamespace
- Elasticsearch\Namespaces\IndicesNamespace
- Elasticsearch\Namespaces\IngestNamespace
- Elasticsearch\Namespaces\NodesNamespace
- Elasticsearch\Namespaces\RemoteNamespace
- Elasticsearch\Namespaces\SnapshotNamespace
- Elasticsearch\Namespaces\TasksNamespace
IMPORTANT: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
current release documentation.
Inline Host Configuration
editInline Host Configuration
editThe most common configuration is telling the client about your cluster: how many nodes, their addresses and ports. If
no hosts are specified, the client will attempt to connect to localhost:9200
.
This behavior can be changed by using the setHosts()
method on ClientBuilder
. The method accepts an array of values,
each entry corresponding to one node in your cluster. The format of the host can vary, depending on your needs (ip vs
hostname, port, ssl, etc)
$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
Notice that the ClientBuilder
object allows chaining method calls for brevity. It is also possible to call the methods
individually:
$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
ElasticON events are back!
Learn about the Elastic Search AI Platform from the experts at our live events.
Register nowWas this helpful?
Thank you for your feedback.