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.

1 Answer 1

11

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.