guandeng / elasticsearch
elasticsearch 组件
dev-main
2024-06-05 06:12 UTC
Requires
- php: >=8.1
- elasticsearch/elasticsearch: ^7.12
- hyperf/guzzle: ~3.1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- hyperf/collection: ~3.1.0
- hyperf/command: ~3.1.0
- hyperf/di: ~3.1.0
- hyperf/pool: ~3.1.0
- hyperf/utils: ~3.1.0
- phpstan/phpstan: ^0.12
This package is auto-updated.
Last update: 2024-09-05 06:43:01 UTC
README
elasticsearch 组件
安装
composer require guandeng/elasticsearch
发布配置
php bin/hyperf.php vendor:publish guandeng/elasticsearch
使用方法
索引
- 创建
namespace App\Indices; use Guandeng\Elasticsearch\Index\AbstractIndex; class Test extends AbstractIndex { protected $index = 'test'; }
- 通过命令创建
php bin/hyperf.php gen:index test
- 查询
use App\Indices\Test; Test::query()->where(...)->search();
- 按查询更新
use App\Indices\Test; Test::query()->where(...)->script(['source' => 'ctx.source.xxx = value'])->updateByQuery();
- 计数
use App\Indices\Test; Test::query()->where(...)->count();
迁移
- 索引
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 }; } }
- 运行迁移
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'; }