tarfin-labs / elastic-aws-client
官方PHP Elasticsearch AWS客户端,与Laravel集成
v2.3.0
2023-05-11 14:36 UTC
Requires
- php: ^7.3|^8.0|^8.1|^8.2
- aws/aws-sdk-php: ^3.80
- elasticsearch/elasticsearch: ^7.3
Requires (Dev)
- orchestra/testbench: ^4.3|^6.0|^7.0|^8.0
- phpunit/phpunit: ^8.4|^9.0
This package is auto-updated.
Last update: 2024-09-11 17:35:26 UTC
README
这是AWS Elasticsearch服务官方PHP Elasticsearch客户端,与Laravel集成。
内容
兼容性
Elastic AWS Client当前版本已与以下配置进行了测试
- PHP 7.3 - 8.0 - 8.1
- Elasticsearch 7.x
- AWS-SDK-PHP ^3.80
安装
该库可以通过Composer安装
composer require tarfin-labs/elastic-aws-client
配置
要更改客户端设置,您需要首先发布配置文件
php artisan vendor:publish --provider="ElasticAwsClient\ServiceProvider"
您可以在config/elastic-aws-client.php
文件中使用\Elasticsearch\ClientBuilder::fromConfig方法支持的一组设置,因为这个工厂在底层使用
return [ 'hosts' => [ [ 'host' => env('ELASTICSEARCH_HOST', 'localhost'), 'port' => env('ELASTICSEARCH_PORT', 9200), 'scheme' => env('ELASTICSEARCH_SCHEME', null), 'user' => env('ELASTICSEARCH_USER', null), 'pass' => env('ELASTICSEARCH_PASS', null), // AWS 'aws' => env('AWS_ELASTICSEARCH_ENABLED', false), 'aws_region' => env('AWS_DEFAULT_REGION', ''), 'aws_key' => env('AWS_ACCESS_KEY_ID', ''), 'aws_secret' => env('AWS_SECRET_ACCESS_KEY', ''), 'aws_credentials' => null ], ], 'sslVerification' => null, 'retries' => null, 'sniffOnStart' => false, 'httpHandler' => null, 'connectionPool' => null, 'connectionSelector' => null, 'serializer' => null, 'connectionFactory' => null, 'endpoint' => null, 'namespaces' => [], ];
使用
在您的代码中使用类型提示\Elasticsearch\Client
或使用resolve
函数来检索客户端实例
namespace App\Console\Commands; use Elasticsearch\Client; use Illuminate\Console\Command; class CreateIndex extends Command { protected $signature = 'create:index {name}'; protected $description = 'Creates an index'; public function handle(Client $client) { $client->indices()->create([ 'index' => $this->argument('name') ]); } }