You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.4 KiB

<?php
namespace ali\alibabacloud\elasticsearch;
use Elasticsearch\ClientBuilder;
class Base extends \ali\alibabacloud\Base
{
protected $config;
/**
* 构造函数
* @date 2022-03-26
*/
public function __construct(array $data = [])
{
parent::__construct($data);
}
// /**
// * 使用AK&SK初始化账号Client
// * @date 2022-04-12
// */
// public function createClient(){
// $config = new Config([
// // 您的AccessKey ID
// "accessKeyId" => $this->config['access_key_id'],
// // 您的AccessKey Secret
// "accessKeySecret" => $this->config['access_key_secret']
// ]);
// // 访问的域名
// $config->endpoint = $this->config['end_point'];
// return new Elasticsearch($config);
// }
/**
* 创建Client
* @date 2022-04-12
*/
public function buildClient(){
$hosts = [
[
'host' => $this->config['public_url'],
'port' => '9200',
'scheme' => 'http',
'user' => $this->config['elastic_user'],
'pass' => $this->config['elastic_password'],
]
];
$client = ClientBuilder::create()->setHosts($hosts)
->setConnectionPool('\Elasticsearch\ConnectionPool\SimpleConnectionPool', [])
->setRetries(10)
->build();
return $client;
}
}