Elasticsearch-php: NoNodesAvailableException in StaticNoPingConnectionPool.php : No alive nodes found in your cluster

Created on 12 Sep 2017  路  21Comments  路  Source: elastic/elasticsearch-php

I use elasticsearch v 5.5.2 with laravel 5.3 - scout v -2.0.
I a trying to executing below code but I am getting this error. NoNodesAvailableException.

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Elasticsearch\ClientBuilder;
use Elastica\Client as ElasticaClient;

class clientController extends Controller
{
    protected $elasticsearch;
    protected $elastica;
    public function __construct()
    {
        $this->elasticsearch = ClientBuilder::create()
                //->setConnectionPool('\Elasticsearch\ConnectionPool\SniffingConnectionPool', [])
                ->build();
        $elasticConfig=['host'=>"locahost",
            "port"=>9200,
            "index"=>'pets'];
        $this->elastica = new  ElasticaClient($elasticConfig);
    }
    public function elasticsearchTest(){

        $param = [
            'index' => 'pets',
            'type' => 'dog',
            'id'=>'1'
        ];
        $res = $this->elasticsearch->get($param);
        dump($res); 
    }
}

NoNodesAvailableException in StaticNoPingConnectionPool.php line 51: No alive nodes found in your cluster
It's working fine in sense. Result:

{
   "_index": "pets",
   "_type": "dog",
   "_id": "1",
   "_version": 1,
   "found": true,
   "_source": {
      "name": "tommy",
      "age": "3",
      "color": "black",
      "gender": "male"
   }
}

Also working on http://localhost:9200/pets/dog/1. Result:

{"_index":"pets","_type":"dog","_id":"1","_version":1,"found":true,"_source":{
    "name":"tommy",
    "age":"3",
    "color":"black",
    "gender":"male"
}
}

I also post this on stackover flow but no response.

Most helpful comment

Hi, I'm using AWS ElasticSearch service and I had a similar error ( Uncaught ElasticsearchCommonExceptionsNoNodesAvailableException: No alive nodes found in your cluster in ...).

I fixed it by doing two things:

1) I added port 80 at the end of the host url (otherwise ES defaults to 9200)
ex: https://{account-specific subdomain}.us-east-2.es.amazonaws.com:80

2) I changed the protocol from https to http.
ex: http://{account-specific subdomain}.us-east-2.es.amazonaws.com:80

Now it works fine!

All 21 comments

I'm not sure tbh. What version of ES-PHP are you using?

Can you add this to help debug the last request?

```php
try {
$res = $this->elasticsearch->get($param);
} catch (Exception $e) {
print_r($this->elasticsearch->transport->getLastConnection()->getLastRequestInfo());
}

Not working shows an error as following.

FatalThrowableError in clientController.php line 36:
Call to a member function getLastRequestInfo() on null

Ah right, doh, the connection wouldn't exist because it didnt execute.

What version of ES-PHP are you using?

Is there anything unusual about how you're running Elasticsearch? In a docker container or something?

Elasticsearch 5.5.2,
php 7,
laravel 5.3

I am using scout to integrate Elasticsearch with laravel.

Ok, I looked at Scout 2.0 branch and it depends on Elasticsearch-PHP 5.0^

Can you paste or gist up your composer.lock file so I can see the exact version of Elasticsearch-PHP that is installed?

Also, repeating my previous question: Is there anything unusual about how you're running Elasticsearch? In a docker container or something?

This is a local elasticsearch right, not something on AWS or other cloud?

No virtual machine. Just local win 7 machine.

composer.txt

I have same problem. Laravel 5.5 Elasticsearch 2.4.6. laravel/scout 3.0 tamayo/laravel-scout-elastic 3.0.8. elasticsearch container from dockerhub. Requesting with curl from app container to elasticsearch container returns elasticsearch's valid json.

I have the same issue.

Using

AWS ElasticsearchService 6.0 (2 nodes)
elasticsearch/elasticsearch 6.0
PHP 7.2
Laravel 5.5
Laravel Scout 3.0
babenkoivan/scout-elasticsearch-driver 3.2

AWS Elasticsearch

I'm trying to connect to an AWS Elasticsearch Service within a VPC, so it doesn't need auth and it runs on https (port 443)

the endpoint that aws gives is in the form https://vpc-<domain>-<id>.us-east-1.es.amazonaws.com

Debugging

I can run curl -X GET 'https://vpc-<domain>-<id>.us-east-1.es.amazonaws.com/_all' and receive the correct response.

I am having trouble connecting via elasticsearch-php. I have tried to specify the port in the endpoint https://vpc-<domain>-<id>.us-east-1.es.amazonaws.com:443 but still nothing.

In StaticNoPingConnectionPool.php line 51:

  No alive nodes found in your cluster

@dasbit did you find anything?
@polyfractal let me know if there is any other information that would help

Same problem here.

Using docker.

I can connect with elasticsearch correctly from localhost:9200 elsewhere. But when it comes to elasticsearch-php. I get No alive nodes found in your cluster.

EDIT

Just found a solution to the problem in this post, you must set the host to the name you assigned to the docker and link php to elasticsearch.

(docker-compose.yml)
php-fpm:
      ...
      links:
          - percona
          - elasticsearch
      ...
elasticsearch:
      build:
        ...

$this->client = ClientBuilder::create()
        ->setHosts(['elasticsearch'])
        ->build();

Hi, I'm using AWS ElasticSearch service and I had a similar error ( Uncaught ElasticsearchCommonExceptionsNoNodesAvailableException: No alive nodes found in your cluster in ...).

I fixed it by doing two things:

1) I added port 80 at the end of the host url (otherwise ES defaults to 9200)
ex: https://{account-specific subdomain}.us-east-2.es.amazonaws.com:80

2) I changed the protocol from https to http.
ex: http://{account-specific subdomain}.us-east-2.es.amazonaws.com:80

Now it works fine!

Thanks @FredGauld. Your two changes fixed my problem too.

(1/1)聽NoNodesAvailableExceptionNo alive nodes found in your cluster

I'm getting same error in my local laravel5.6 project and also using this elastic version 'elasticsearch/elasticsearch 6.0'
please help me how i can solve this issue.
And most important things

where i can set given array in laravel setup.
$params = [
'index' => 'my_index',
'type' => 'my_type',
'id' => 'my_id',
'body' => ['testField' => 'abc']
];
$response = $client->index($params);
print_r($response);

'elasticsearch/elasticsearch 6.0'
Same error

thanks @MikeMajara It works for me

Hello guys,

Unfortunately I am getting this same error. But strange part is, it is working perfectly fine on my localhost:9200

But when I connect this with my elasticsearch server i.e host URL is changed, this throws the above error: "No alive nodes found in your cluster"

I tried every possible solution but couldn't find anyone facing this similar issue.

In short, Elastic search working fine on localhost, but not working when I connect with other hosting server. Tried with 443 HTTPS and 80,9200 HTTP as well.

Any help will be appreciated. Thanks

Problem: connection client to elasticsearch.
Solution: https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_configuration.html

The most common configuration is telling the client about your cluster: how many nodes, their addresses and ports. If no hosts are specified, the client will attempt to connect to localhost:9200.

$client = ClientBuilder::create()->setHosts(['<elastic_host>:<elastic_port>'])->build();
...

I had a similar problem, it turned out to be an invalid hostname; https://github.com/elastic/elasticsearch-php/issues/509#issuecomment-491825174

huh this is so annoying. its happening only in linux box (redhat). the same code perfectly working from my laptop windows with ip address. not a single line changed but somehow it gives up connecting to host. both client and server on same box and I am using public ip to talk to server

@chamarts do you still have the issue? Did you build the $client specifying the host?

$client = ClientBuilder::create()->setHosts(['<elastic_host>:<elastic_port>'])->build();

where <elastic_host> is the hostname or IP address (default to localhost) and <elastic_port> is the port (default to 9200).
Moreover, did you check the response by @benanderton here?
Let me knowm, thanks!

Closing this issue due to inactivity.

Thanks @MikeMajara .

Was this page helpful?
0 / 5 - 0 ratings

Related issues

amorphine picture amorphine  路  6Comments

m9rco picture m9rco  路  3Comments

angelxmoreno picture angelxmoreno  路  3Comments

thinkspill picture thinkspill  路  3Comments

KarboniteKream picture KarboniteKream  路  5Comments