Andreas Hunter
Andreas Hunter

Reputation: 5014

laravel 6 + elasticsearch-php 7.6 + xampp: No alive nodes found in your cluster

I use elasticsearch-php in my laravel app with XAMPP.

Versions:

AppServiceProvider.php code where I register my custom scout driver:

public function boot()
{
    $this->app->singleton('elasticsearch', function () {
        return ClientBuilder::create()
                ->setHosts([
                    'http://localhost/scout/public'
                ])
                ->build();
    });

    resolve(EngineManager::class)->extend('elasticsearch', function () {
        return new ElasticSearchEngine(
            app('elasticsearch')
        );
    });
}

My custom search engine code:

<?php 

namespace App\Search\Engines;

use Laravel\Scout\Engines\Engine;
use Laravel\Scout\Builder;
use Elasticsearch\Client;

class ElasticSearchEngine extends Engine
{
    protected $client;

    public function __construct(Client $client)
    {
        $this->client = $client;
    }

    /**
     * Update the given model in the index.
     *
     * @param  \Illuminate\Database\Eloquent\Collection  $models
     * @return void
     */
    public function update($models)
    {
        $models->each(function($model) {
            $params = [
                'index' => $model->searchableAs(),
                'type' => $model->searchableAs(),
                'id' => $model->id,
                'body' => $model->toSearchableArray()
            ];

            $this->client->index($params);
        });
    }
}

In my case when I try run command php artisan scout:import App\User Elasticsearch package return error with message:

Elasticsearch\Common\Exceptions\NoNodesAvailableException : No alive nodes found in your cluster

enter image description here

How I can solve my problem? Maybe here problem with hosts or xampp setting?

Upvotes: 4

Views: 1989

Answers (1)

Otabek Mansurov
Otabek Mansurov

Reputation: 218

First of all, DON’T PANIC :) I think what you don't have Elasticsearch installed. It will take 5 minutes to install Elasticsearch and solve your problem.

Installation

  • Download and unpack the Elasticsearch official distribution.
  • Run bin/elasticsearch on Linux or macOS. Run bin\elasticsearch.bat on Windows.
  • Run curl -X GET http://localhost:9200

Upvotes: 2

Related Questions