アンドレアス・ハンター:
私が使用しelasticsearch-PHPを XAMPPと私のlaravelアプリで。
バージョン:
- PHP:7.3
- Laravel:^ 6.2
- Elasticsearch:^ 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);
});
}
}
私の場合は、runコマンドしようとすると、php artisan scout:import App\User
メッセージを表示してElasticsearchパッケージリターンエラー:
Elasticsearch \共通\例外\ NoNodesAvailableException:いいえ生きているノードクラスタで見つかりました
どのように私は私の問題を解決することができますか?たぶん、ホストまたはXAMPPの設定に問題があることをここに?
タラマンスロフ:
まず、:)慌てないでください、私はあなたがElasticsearchがインストールされていないものだと思います。それはElasticsearchをインストールして、あなたの問題を解決するために5分かかります。
インスト
- ダウンロード Elasticsearch公式配信をして解凍します。
- 実行
bin/elasticsearch
上のLinuxやMacOSの。実行bin\elasticsearch.bat
上のWindows。 - ラン
curl -X GET http://localhost:9200