babenkoivan / elastic-client by babenkoivan

The official PHP Elasticsearch client integrated with Laravel
2,506,227
50
3
Package Data
Maintainer Username: babenkoivan
Maintainer Contact: babenko.i.a@gmail.com (Ivan Babenko)
Package Create Date: 2019-10-27
Package Last Update: 2024-06-18
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-12-18 03:00:35
Package Statistics
Total Downloads: 2,506,227
Monthly Downloads: 85,624
Daily Downloads: 4,077
Total Stars: 50
Total Watchers: 3
Total Forks: 8
Total Open Issues: 0

Elastic Client

Latest Stable Version Total Downloads License Tests Code style Static analysis Donate PayPal


The official PHP Elasticsearch client integrated with Laravel.

Contents

Compatibility

The current version of Elastic Client has been tested with the following configuration:

  • PHP 7.2-8.0
  • Elasticsearch 7.x

Installation

The library can be installed via Composer:

composer require babenkoivan/elastic-client

Configuration

To change the client settings you need to publish the configuration file first:

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

You can use any settings supported by \Elasticsearch\ClientBuilder::fromConfig method in the config/elastic.client.php file as this factory is used under the hood:

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

Usage

Type hint \Elasticsearch\Client or use resolve function to retrieve the client instance in your code:

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')
        ]);
    }
}