HTTP Authentication

edit

If your Elasticsearch server is protected by HTTP Authentication, you need to provide the credentials to ES-PHP so that requests can be authenticated server-side. Authentication credentials are provided as part of the host array when instantiating the client:

$hosts = [
    'http://user:pass@localhost:9200',       // HTTP Basic Authentication
    'http://user2:[email protected]:9200' // Different credentials on different host
];

$client = ClientBuilder::create()
                    ->setHosts($hosts)
                    ->build();

Credentials are provided per-host, which allows each host to have their own set of credentials. All requests sent to the cluster will use the appropriate credentials depending on the node being talked to.