friendsofhyperf/elasticsearch

A component for elasticsearch

0.6.1 2022-03-21 02:52 UTC

This package is auto-updated.

Last update: 2022-05-21 03:11:58 UTC


README

Latest Stable Version Total Downloads GitHub license

A component for elasticsearch

Installation

composer require friendsofhyperf/elasticsearch

Publish configure

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

Usage

Index

  • Create
namespace App\Indices;

use FriendsOfHyperf\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 FriendsOfHyperf\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 FriendsOfHyperf\Elasticsearch\ClientProxy;

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