Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connection Error #1088

Closed
JulieVelghe opened this issue Dec 13, 2020 · 8 comments
Closed

connection Error #1088

JulieVelghe opened this issue Dec 13, 2020 · 8 comments

Comments

@JulieVelghe
Copy link

Summary of problem or feature request

I've used this client to use elasticsearch in a craft cms website. To develop, I use mamp pro 4 for windows and github desktop to get my repo. I now got an error in my code, when trying to ping: no alive nodes in cluster. However, when calling my endpoint in lets say postman, I get an ok response. Also, getting the repo on my mac tower, again with mamp pro as local webhost, and sourcetree to fetch the repo, all seems well, no errors, nothing broken. Does anyone have a clue where to look for the issue?

Code snippet of problem

System details

os: windows 10
mamp 4.2.0
php 7.3.7
ES-PHP : ^7.6

  • Operating System
  • PHP Version
  • ES-PHP client version
  • Elasticsearch version
@ezimuel
Copy link
Contributor

ezimuel commented Dec 17, 2020

@JulieVelghe can you paste the PHP code for the connection to Elasticsearch that you are using? Thanks.

@JulieVelghe
Copy link
Author

Hi,
to connect we do this:

$hosts = [
            $host,
        ];

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

where our host is like this: https://elastic:xxxxxxx@60724656c51546f09a55d9db65a2a127.eu-central-1.aws.cloud.es.io:9243

Then the first thing we do when we get to the page in our craft admin is a ping:

        try {
            $this->client->ping();
            return true;
        }
        catch(\Throwable $t) {
            return false;
        }

I do want to note, this code works on other machines.

@JulieVelghe
Copy link
Author

Is there perhaps some other program I need to have to be able to run this? Or any special php dll's? Or something to that extend?

@ezimuel
Copy link
Contributor

ezimuel commented Jan 14, 2021

@JulieVelghe can you try to use the following configuration?

use Elasticsearch\ClientBuilder;

$client = ClientBuilder::create()
    ->setHosts(['https://60724656c51546f09a55d9db65a2a127.eu-central-1.aws.cloud.es.io:9243'])
    ->setBasicAuthentication('elastic','xxxxxxx')
    ->build();

Moreover, are you sure the port is 9243? Usually, it should be 443 (https) is the host is public.
Please give a try and let me know, thanks!

@Smokietr
Copy link

Try this if you are running on localhost. #1101

@JulieVelghe
Copy link
Author

JulieVelghe commented Feb 5, 2021 via email

@JulieVelghe
Copy link
Author

JulieVelghe commented Mar 22, 2021 via email

@richgoldmd
Copy link

In ElasticSearchPhpHandler.php we have this:

   private function createPsr7Request(array $ringPhpRequest)
    {
        // fix for uppercase 'Host' array key in elasticsearch-php 5.3.1 and backward compatible
        // https://github.com/aws/aws-sdk-php/issues/1225
        $hostKey = isset($ringPhpRequest['headers']['Host'])? 'Host' : 'host';
        // Amazon ES listens on standard ports (443 for HTTPS, 80 for HTTP).
        // Consequently, the port should be stripped from the host header.
        $parsedUrl = parse_url($ringPhpRequest['headers'][$hostKey][0]);
        if (isset($parsedUrl['host'])) {
            $ringPhpRequest['headers'][$hostKey][0] = $parsedUrl['host'];
        }

it also appears as if any client options (like skip SSL Verify) are dropped at this point as well (the reside in $request['client'] which is removed by the above method.

@ezimuel ezimuel closed this as completed Mar 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants