我在我的laravel应用程序中使用elasticsearch-php和XAMPP。
版本:
注册我的自定义童子军司机的AppServiceProvider.php代码:
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')
);
});
}我的自定义搜索引擎代码:
<?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);
});
}
}在我的例子中,当我尝试运行命令php artisan scout:import App\User Elasticsearch包时,返回错误的消息如下:
Elasticsearch\Common\Exceptions\NoNodesAvailableException :集群中没有找到活动节点

我怎样才能解决我的问题?也许这里存在主机或xampp设置的问题?
发布于 2020-03-02 11:31:26
首先,不要惊慌:)我认为您没有安装Elasticsearch。安装Elasticsearch并解决您的问题需要5分钟。
安装
bin/elasticsearch on Linux或macOS。在bin\elasticsearch.bat Windows上运行。curl -X GET http://localhost:9200https://stackoverflow.com/questions/60484170
复制相似问题