ajaybc
ajaybc

Reputation: 4059

Elasticsearch PHP client throwing exception "No alive nodes found in your cluster"

I am trying to do a scan and scroll operation on an index as shown in the example :

$client = ClientBuilder::create()->setHosts([MYESHOST])->build();
$params = [
    "search_type" => "scan",    // use search_type=scan
    "scroll" => "30s",          // how long between scroll requests. should be small!
    "size" => 50,               // how many results *per shard* you want back
    "index" => "my_index",
    "body" => [
        "query" => [
            "match_all" => []
        ]
    ]
];

$docs = $client->search($params);   // Execute the search
$scroll_id = $docs['_scroll_id'];   // The response will contain no results, just a _scroll_id

// Now we loop until the scroll "cursors" are exhausted
while (\true) {

    // Execute a Scroll request
    $response = $client->scroll([
            "scroll_id" => $scroll_id,  //...using our previously obtained _scroll_id
            "scroll" => "30s"           // and the same timeout window
        ]
    );

    // Check to see if we got any search hits from the scroll
    if (count($response['hits']['hits']) > 0) {
        // If yes, Do Work Here

        // Get new scroll_id
        // Must always refresh your _scroll_id!  It can change sometimes
        $scroll_id = $response['_scroll_id'];
    } else {
        // No results, scroll cursor is empty.  You've exported all the data
        break;
    }
}

The first $client->search($params) API call executes fine and I am able to get back the scroll id. But $client->scroll() API fails and I am getting the exception : "Elasticsearch\Common\Exceptions\NoNodesAvailableException No alive nodes found in your cluster"

I am using Elasticsearch 1.7.1 and PHP 5.6.11

Please help

Upvotes: 32

Views: 19469

Answers (12)

Nilay Dagdemir
Nilay Dagdemir

Reputation: 284

Try:

  1. Stop your elasticsearch service if it's already running
  2. Go to your elasticsearch directory via terminal, run:

    > ./bin/elasticsearch
    

This worked for me.

Upvotes: 0

Yao Li
Yao Li

Reputation: 2286

If you setup Elasticsearch server in docker as the doc, https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html

But it uses a different network (networks: - esnet) from other services and it cannot talk to the application network. After remove the networks setting and it works well.

Upvotes: 0

Yao Li
Yao Li

Reputation: 2286

I setup Elasticsearch server in docker as the doc, https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html

But it uses a different network (networks: - esnet) and it cannot talk to the application network. After remove the networks setting and it works well.

Upvotes: 0

Imran Mushtaq
Imran Mushtaq

Reputation: 147

That error basically means it can't find your cluster, likely due to misconfiguration on either the client's side or the server's side.

Upvotes: 1

Đào Minh Hạt
Đào Minh Hạt

Reputation: 2930

Maybe you should try to telnet on your machine telnet [your_es_host] [your_es_ip] to check if you can access to it.

If not please try to open that port or disable your machine's firewall.

Upvotes: 1

R. lori
R. lori

Reputation: 31

I found the php driver for elasticsearch is riddled with issues, the solution I had was to just implement the RESTful API with curl via php, Everything worked much quicker and debugging was much easier

Upvotes: 3

user7095134
user7095134

Reputation:

restart the elastic search service and set the network host to local "127.0.0.1".

Upvotes: 2

mygir
mygir

Reputation: 1

Uncomment in elasticsearch.yml:

network.host:198....

And set to:

127.0.0.1

Like this:

# Set the bind address to a specific IP (IPv4 or IPv6):
#
 network.host: 127.0.0.1
#
# Set a custom port for HTTP:
#
# http.port: 9200
#

I use Elasticsearch 2.2 in Magento 2 under LXC container.

Upvotes: 0

Tomasz Swider
Tomasz Swider

Reputation: 2382

I have had the same problem with scroll and it was working with certain indexes but not with others. It must have had been a bug in the driver as it went away after I have updated elasticsearch/elasticsearch package from 2.1.3 to 2.2.0

Upvotes: 0

Farid Movsumov
Farid Movsumov

Reputation: 12725

Check if your server running with following command.

service elasticsearch status

I had the same problem and solved it.

I have added script.disable_dynamic: true to elasticsearch.yml as explained in Digitalocan tutorial https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-elasticsearch-on-ubuntu-14-04

So elasticsearch server was not started.

I removed following line from elasticsearch.yml

script.disable_dynamic: true

Upvotes: 2

Johnathan Kanarek
Johnathan Kanarek

Reputation: 854

I would recommend on using php curl lib directly for elasticsearch queries. I find it easier to use than any other elasticsearch client lib, you can simulate any query using cli curl and you can find many examples, documentation and discussions in the internet.

Upvotes: 1

Greg
Greg

Reputation: 6648

I would guess the example is not up to date with the version you're using (the link you've provided is to 2.0, and you are sauing you use 1.7.1). Just add inside the loop:

try {
      $response = $client->scroll([
            "scroll_id" => $scroll_id,  //...using our previously obtained _scroll_id
            "scroll" => "30s"           // and the same timeout window
        ]
    );
}catch (Elasticsearch\Common\Exceptions\NoNodesAvailableException $e) {
   break;
}

Upvotes: 2

Related Questions