ElasticSearch 協(xié)程客戶端組件
協(xié)程版 ElasticSearch Client,對(duì)官方客戶端的協(xié)程化移植
組件要求
- easyswoole/spl: ^1.3
- easyswoole/http-client: ^1.3
- easyswoole/swoole-ide-helper: ^1.3
安裝方法
composer require easyswoole/elasticsearch
倉(cāng)庫(kù)地址
Client 用法
<?php
$config = new \EasySwoole\ElasticSearch\Config([
'host' => '127.0.0.1',
'port' => 9200
]);
$elasticsearch = new \EasySwoole\ElasticSearch\ElasticSearch($config);
go(function () use ($elasticsearch) {
$bean = new \EasySwoole\ElasticSearch\RequestBean\Search();
$bean->setIndex('my_index');
$bean->setType('my_type');
$bean->setBody(['query' => ['matchAll' => []]]);
$response = $elasticsearch->client()->search($bean)->getBody();
var_dump(json_decode($response, true));
});
x-pack 驗(yàn)證
當(dāng) elasticsearch
開啟 x-pack
登錄驗(yàn)證時(shí),只需在 config
中再傳入用戶名密碼即可
<?php
$config = new \EasySwoole\ElasticSearch\Config([
'host' => '127.0.0.1',
'port' => 9200,
'username' => 'elastic',
'password' => '123456'
]);
$elasticsearch = new \EasySwoole\ElasticSearch\ElasticSearch($config);
修改 http 為 https
<?php
$config = new \EasySwoole\ElasticSearch\Config([
'host' => '127.0.0.1',
'port' => 9200,
'username' => 'elastic',
'password' => '123456',
'scheme' => 'https'
]);
$elasticsearch = new \EasySwoole\ElasticSearch\ElasticSearch($config);