Reputation: 5014
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
How I can solve my problem? Maybe here problem with hosts or xampp setting?
Upvotes: 4
Views: 1989
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
bin/elasticsearch
on Linux or macOS. Run bin\elasticsearch.bat
on Windows.curl -X GET http://localhost:9200
Upvotes: 2