guandeng/elasticsearch

A component for elasticsearch

dev-main 2023-12-29 00:41 UTC

This package is auto-updated.

Last update: 2024-04-29 01:19:13 UTC


README

Latest Stable Version Total Downloads GitHub license

A component for elasticsearch

Installation

composer require guandeng/elasticsearch

Publish configure

php bin/hyperf.php vendor:publish guandeng/elasticsearch

Usage

Index

  • Create
namespace App\Indices;

use Guandeng\Elasticsearch\Index\AbstractIndex;

class Test extends AbstractIndex
{
    protected $index = 'test';
}
  • Create by command
php bin/hyperf.php gen:index test
  • Query
use App\Indices\Test;

Test::query()->where(...)->search();
  • UpdateByQuery
use App\Indices\Test;

Test::query()->where(...)->script(['source' => 'ctx.source.xxx = value'])->updateByQuery();
  • Count
use App\Indices\Test;

Test::query()->where(...)->count();

Migrate

  • Index
namespace App\Indices;

use Guandeng\Elasticsearch\Index\AbstractIndex;

class Test extends AbstractIndex
{
    protected $index = 'test';
    protected $type = '_doc';
    protected $settings = [
        // your settings
    ];
    protected $properties = [
        // your properties
    ];

    public function getMigration(): Closure
    {
        return function ($index) {
            // migrate data
        };
    }
}
  • Run migrate
php bin/hyperf.php elasticsearch:migrate "App\\Indices\\Test" [--migrate] [--update] [--recreate]

ClientProxy

namespace App\Proxy;

use Guandeng\Elasticsearch\ClientProxy;

class FooClient extends ClientProxy
{
    protected $poolName = 'foo';
}