public function ClientManager::getClientForCluster in Elasticsearch Connector 8.2
Same name and namespace in other branches
- 8.7 src/ElasticSearch/ClientManager.php \Drupal\elasticsearch_connector\ElasticSearch\ClientManager::getClientForCluster()
- 8.5 src/ElasticSearch/ClientManager.php \Drupal\elasticsearch_connector\ElasticSearch\ClientManager::getClientForCluster()
- 8.6 src/ElasticSearch/ClientManager.php \Drupal\elasticsearch_connector\ElasticSearch\ClientManager::getClientForCluster()
Get the Elasticsearch client required by the functionality.
Parameters
Cluster $cluster:
Return value
\nodespark\DESConnector\ClientInterface
Throws
\Exception
Overrides ClientManagerInterface::getClientForCluster
File
- src/
ElasticSearch/ ClientManager.php, line 49
Class
- ClientManager
- Class ClientManager.
Namespace
Drupal\elasticsearch_connector\ElasticSearchCode
public function getClientForCluster(Cluster $cluster) {
$hosts = [
[
'url' => $cluster->url,
'options' => $cluster->options,
],
];
$hash = json_encode($hosts);
if (!isset($this->clients[$hash])) {
$options = array(
'hosts' => array(
$cluster
->getRawUrl(),
),
'options' => array(),
'curl' => array(),
);
if ($cluster->options['use_authentication']) {
$options['auth'] = [
$cluster->url => [
'username' => $cluster->options['username'],
'password' => $cluster->options['password'],
'method' => $cluster->options['authentication_type'],
],
];
}
$this->moduleHandler
->alter('elasticsearch_connector_load_library_options', $options);
$this->clients[$hash] = $this->clientManagerFactory
->create($options);
}
return $this->clients[$hash];
}