A component for elasticsearch
composer require guandeng/elasticsearch
php bin/hyperf.php vendor:publish guandeng/elasticsearch
- 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();
- 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]
namespace App\Proxy;
use Guandeng\Elasticsearch\ClientProxy;
class FooClient extends ClientProxy
{
protected $poolName = 'foo';
}