Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

how to connect es with elasticsearch-php-sdk #22

Closed
y80x86ol opened this issue Mar 18, 2019 · 5 comments
Closed

how to connect es with elasticsearch-php-sdk #22

y80x86ol opened this issue Mar 18, 2019 · 5 comments

Comments

@y80x86ol
Copy link

y80x86ol commented Mar 18, 2019

I install open distro for elasticsearch,and open ssl, like "https://127.0.0.1:9200", use default admin account.

but when i use elasticsearch-php-sdk to connect es,it tell me "SSL Problem Received fatal alert: unknown_ca". Am I wrong?

but I can access it by browser.

https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_security.html

thanks!

@aetter
Copy link
Contributor

aetter commented Mar 18, 2019

Hi @y80x86ol, did you add the $myCert = 'path/to/cacert.pem'; line on that page for self-signed certificates? The default demo certificate that Open Distro for Elasticsearch uses is self-signed.

@y80x86ol
Copy link
Author

Hi @y80x86ol, did you add the $myCert = 'path/to/cacert.pem'; line on that page for self-signed certificates? The default demo certificate that Open Distro for Elasticsearch uses is self-signed.

I add the cacert pem in my code, but still can't connection es.
ps: i used the Open Distro for Elasticsearch demo certificate

@aetter
Copy link
Contributor

aetter commented Mar 25, 2019

Hi @y80x86ol, I was able to get this working after some struggles. Can you try the following?

<?php

require 'vendor/autoload.php';

use Elasticsearch\ClientBuilder;

$hosts = ['https://admin:admin@localhost:9200'];
$myCert = '/full/path/to/root-ca.pem';

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

$params = [
    'index' => 'test-index',
    'type' => '_doc',
    'id' => '1',
    'body' => ['testField' => 'abc']
];

$response = $client->index($params);
print_r($response);

?>

Then at the command line:

$ php -n -S 0.0.0.0:8000 index.php

And navigate to 0.0.0.0:8000 in your browser. Let me know. Thanks!

@y80x86ol
Copy link
Author

y80x86ol commented Mar 26, 2019

@aetter thank you for your reply!
I tried you code ,but still echo 'No alive nodes found in your cluster'.

I disabling SSL verification,it works!

code like this:

$hosts = ['https://admin:admin@127.0.0.1:9210'];

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

there are some same issues in other github:
elastic/elasticsearch-php#854
elastic/elasticsearch-php#850

@aetter
Copy link
Contributor

aetter commented Mar 26, 2019

Hi @y80x86ol, gotcha, I'm going to close this one out. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants