hyperf-ext / elasticsearch
The Hyperf Elasticsearch package.
Installs: 10 074
Dependents: 2
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 2
Open Issues: 2
Requires
- php: >=7.3
- ext-swoole: >=4.5
- elasticsearch/elasticsearch: ^7.13
- hyperf/config: ~2.2.0
- hyperf/di: ~2.2.0
- hyperf/framework: ~2.2.0
- hyperf/guzzle: ~2.2.0
- hyperf/pool: ~2.2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- hyperf/testing: ~2.2.0
- mockery/mockery: ^1.0
- phpstan/phpstan: ^0.12
- swoole/ide-helper: dev-master
Suggests
- hyperf/logger: Allows for client-level logging and tracing
This package is auto-updated.
Last update: 2024-10-29 06:19:28 UTC
README
该组件为 Elasticsearch 客户端的创建提供了工厂类封装。同时,得益于 hyperf/guzzle 协程组件,该组件为 Elasticsearch 的 Handler
实现了协程化,可配置为连接池模式。
安装
composer require hyperf-ext/elasticsearch
如启用 Elasticsearch 客户端日志则需安装
hyperf/logger
组件。
发布配置
php bin/hyperf.php vendor:publish hyperf-ext/elasticsearch
配置
[ /* |-------------------------------------------------------------------------- | 自定义 Elasticsearch 客户端配置 |-------------------------------------------------------------------------- | | 详细设置请参阅: | http://www.elasticsearch.org/guide/en/elasticsearch/client/php-api/current/_configuration.html */ 'client' => [ 'hosts' => [ 'http://localhost:9200', ], 'retries' => 1, ], /* |-------------------------------------------------------------------------- | 连接池设置 |-------------------------------------------------------------------------- */ 'pool' => [ 'enabled' => true, 'min_connections' => 1, 'max_connections' => 30, 'wait_timeout' => 3.0, 'max_idle_time' => 60.0, ], /* |-------------------------------------------------------------------------- | Elasticsearch 日志设置 |-------------------------------------------------------------------------- | | 启用日志需安装 `hyperf/logger` 组件。 */ 'logger' => [ 'enabled' => false, 'name' => 'elasticsearch', 'group' => 'default', ], ];
使用
只需简单的注入 Elasticsearch\Client
类即可获取客户端实例对象,所有相关配置都已在 HyperfExt\Elasticsearch\ClientFactory
工厂类中完成。
<?php use Elasticsearch\Client; use Hyperf\Utils\ApplicationContext; $client = ApplicationContext::getContainer()->get(Client::class); $info = $client->info();