簡體   English   中英

laravel 6 + elasticsearch-php 7.6 + xampp:在您的集群中找不到活動節點

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

我在帶有 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 設置的問題?

首先,不要恐慌 :) 我認為你沒有安裝 Elasticsearch。 安裝 Elasticsearch 並解決您的問題需要 5 分鍾。

安裝

  • 下載並解壓 Elasticsearch 官方發行版。
  • LinuxmacOS上運行bin/elasticsearch Windows上運行bin\\elasticsearch.bat
  • 運行curl -X GET http://localhost:9200

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM