【问题标题】:laravel 6 + elasticsearch-php 7.6 + xampp: No alive nodes found in your clusterlaravel 6 + elasticsearch-php 7.6 + xampp:在您的集群中找不到活动节点
【发布时间】: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


    【解决方案1】:

    首先,不要惊慌 :) 我认为您没有安装 Elasticsearch。安装 Elasticsearch 并解决您的问题需要 5 分钟。

    安装

    • Download 并解压 Elasticsearch 官方发行版。
    • 在 Linux 或 ma​​cOS 上运行 bin/elasticsearch。在 Windows 上运行 bin\elasticsearch.bat。
    • 运行curl -X GET http://localhost:9200

    【讨论】:

    • 哇!我不认为要让弹性搜索工作,需要某种外部程序安装。我现在重新导入了索引表,一切正常。谢谢你的回答。 @Otabek Mansurov
    猜你喜欢
    • 2021-03-23
    • 1970-01-01
    • 2021-01-04
    • 1970-01-01
    • 2015-12-11
    • 2018-01-17
    • 2016-05-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多