【发布时间】:2020-06-14 11:21:15
【问题描述】:
我在带有 XAMPP 的 laravel 应用中使用 elasticsearch-php。
版本:
- PHP:7.3
- Laravel:^6.2
- 弹性搜索:^7.6
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 package return error with message:
Elasticsearch\Common\Exceptions\NoNodesAvailableException : 不存在 在您的集群中找到的节点
如何解决我的问题?也许这里的主机或 xampp 设置有问题?
【问题讨论】:
标签: php laravel elasticsearch xampp