6

I have activated default "elastic" user and set a password for that user. I am using elasticsearch-php to connect and query my elasticsearch. It was working good, but after activating the password I cannot connect using my previous code.

While looking for providing authentication information with the ClientBuilder, I only get configurations regarding ssh connection. Did not find anything how can I use my elasticsearch username and password with the connection.

$hosts = ['127.0.0.1:9200'];
$es_user = 'elastic';
$es_pass = 'MY_PASS';
$elasticsearch = Elasticsearch\ClientBuilder::create()->setHosts($hosts)->build();

I am wondering how can I use my username/password in the connection above.

Mainuddin
  • 416
  • 5
  • 15

1 Answers1

10

You can do it with an extended host configuration like this:

$hosts = [
    [
        'host' => '127.0.0.1',
        'port' => '9200',
        'user' => 'elastic',
        'pass' => 'MY_PASS'
    ]
];
$elasticsearch = Elasticsearch\ClientBuilder::create()
                    ->setHosts($hosts)
                    ->build();
Val
  • 207,596
  • 13
  • 358
  • 360