adiliogobira/elastic-client

官方 PHP Elasticsearch 客户端,与 Laravel 集成

v1.1.0 2020-07-09 10:19 UTC

This package is auto-updated.

Last update: 2024-09-11 02:14:58 UTC


README

Latest Stable Version Total Downloads License Build Status Donate PayPal Donate Amazon

官方 PHP Elasticsearch 客户端,与 Laravel 集成。

内容

兼容性

Elastic Client 的当前版本已与以下配置进行测试

  • PHP 7.2-7.4
  • Elasticsearch 7.x

安装

可以通过 Composer 安装此库

composer require babenkoivan/elastic-client

配置

要更改客户端设置,您需要首先发布配置文件

php artisan vendor:publish --provider="ElasticClient\ServiceProvider"

您可以在 config/elastic.client.php 文件中使用 \Elasticsearch\ClientBuilder::fromConfig 方法支持的所有设置,因为这个工厂在底层使用

return [
    'hosts' => [
        env('ELASTIC_HOST', 'localhost:9200'),
    ]
];

使用

在您的代码中使用类型提示 \Elasticsearch\Client 或使用 resolve 函数来检索客户端实例

namespace App\Console\Commands;

use Elasticsearch\Client;
use Illuminate\Console\Command;

class CreateIndex extends Command
{
    protected $signature = 'create:index {name}';

    protected $description = 'Creates an index';

    public function handle(Client $client)
    {
        $client->indices()->create([
            'index' => $this->argument('name')
        ]);
    }
}