From d4febf9008c2550e6eae3a2189e5a32a8fd8e6d9 Mon Sep 17 00:00:00 2001 From: Carl Casbolt Date: Tue, 18 Jun 2019 16:08:27 +0100 Subject: [PATCH] Configuration to allow request_options to be used I have found that I need to set some of the client request options for the transport layer within the Connection via the Manager. This change allows for any of the GuzzleHttp Client Request Options to be set in yaml per index and used within the elastic search libraries. - Carl. --- DependencyInjection/Configuration.php | 5 +++++ Resources/doc/configuration.md | 11 ++++++++--- Service/ManagerFactory.php | 1 + 3 files changed, 14 insertions(+), 3 deletions(-) mode change 100644 => 100755 DependencyInjection/Configuration.php mode change 100644 => 100755 Resources/doc/configuration.md mode change 100644 => 100755 Service/ManagerFactory.php diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php old mode 100644 new mode 100755 index 0883bcad..12c9dc0d --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -117,6 +117,11 @@ private function getManagersNode() ->prototype('scalar') ->end() ->end() + ->arrayNode('client_options') + ->defaultValue([]) + ->info('Sets client params for connection.') + ->prototype('variable')->end() + ->end() ->arrayNode('settings') ->defaultValue( [ diff --git a/Resources/doc/configuration.md b/Resources/doc/configuration.md old mode 100644 new mode 100755 index 16498966..f27112b6 --- a/Resources/doc/configuration.md +++ b/Resources/doc/configuration.md @@ -22,7 +22,7 @@ ongr_elasticsearch: max_gram: 20 managers: default: - index: + index: hosts: - 127.0.0.1:9200 index_name: ongr-default @@ -33,12 +33,17 @@ ongr_elasticsearch: logger: true #default %kernel.debug% mappings: - AcmeBarBundle #Scans all bundle documents + client_options: # http://docs.guzzlephp.org/en/stable/request-options.html + allow_redirects: false + connect_timeout: 5 + timeout: 20 + custom: - index: + index: hosts: - 10.0.0.1:9200 #default 127.0.0.1:9200 index_name: ongr-custom mappings: AcmeBundle: document_dir: Document -``` \ No newline at end of file +``` diff --git a/Service/ManagerFactory.php b/Service/ManagerFactory.php old mode 100644 new mode 100755 index 6b8bbf3f..7e11c0ef --- a/Service/ManagerFactory.php +++ b/Service/ManagerFactory.php @@ -102,6 +102,7 @@ public function createManager($managerName, $connection, $analysis, $managerConf $client = ClientBuilder::create(); $client->setHosts($connection['hosts']); + $client->setConnectionParams(['client' => $connection['client_options']]); $client->setTracer($this->tracer); if ($this->logger && $managerConfig['logger']['enabled']) {