diff --git a/src/module-elasticsuite-core/Api/Client/ClientConfigurationInterface.php b/src/module-elasticsuite-core/Api/Client/ClientConfigurationInterface.php index 9e84a7772..3715047ea 100644 --- a/src/module-elasticsuite-core/Api/Client/ClientConfigurationInterface.php +++ b/src/module-elasticsuite-core/Api/Client/ClientConfigurationInterface.php @@ -79,6 +79,13 @@ public function getHttpAuthPassword(); */ public function getMaxParallelHandles(); + /** + * Get the maximum number of seconds to wait for a response + * + * @return int + */ + public function getReadTimeout(); + /** * Client config options. * diff --git a/src/module-elasticsuite-core/Client/ClientBuilder.php b/src/module-elasticsuite-core/Client/ClientBuilder.php index 765ff4b71..ea6269f30 100644 --- a/src/module-elasticsuite-core/Client/ClientBuilder.php +++ b/src/module-elasticsuite-core/Client/ClientBuilder.php @@ -109,6 +109,17 @@ public function build($options = []) $clientBuilder->setSelector($selector); } + $connectionParams = ['client' => []]; + if (isset($options['timeout'])) { + $connectionParams['client']['timeout'] = $options['timeout']; + } + if (isset($options['connection_timeout'])) { + $connectionParams['client']['connect_timeout'] = $options['connection_timeout']; + } + if (count($connectionParams['client'])) { + $clientBuilder->setConnectionParams($connectionParams); + } + return $clientBuilder->build(); } diff --git a/src/module-elasticsuite-core/Client/ClientConfiguration.php b/src/module-elasticsuite-core/Client/ClientConfiguration.php index 8af3ddfb6..585884aa6 100644 --- a/src/module-elasticsuite-core/Client/ClientConfiguration.php +++ b/src/module-elasticsuite-core/Client/ClientConfiguration.php @@ -112,6 +112,14 @@ public function getMaxParallelHandles() return (int) $this->getElasticsearchClientConfigParam('max_parallel_handles'); } + /** + * {@inheritdoc} + */ + public function getReadTimeout() + { + return (int) $this->getElasticsearchClientConfigParam('timeout'); + } + /** * {@inheritDoc} */ @@ -125,6 +133,8 @@ public function getOptions() 'http_auth_pwd' => $this->getHttpAuthPassword(), 'is_debug_mode_enabled' => $this->isDebugModeEnabled(), 'max_parallel_handles' => $this->getMaxParallelHandles(), + 'timeout' => $this->getReadTimeout(), + 'connection_timeout' => $this->getConnectionTimeout(), ]; return $options; diff --git a/src/module-elasticsuite-core/etc/adminhtml/system.xml b/src/module-elasticsuite-core/etc/adminhtml/system.xml index 3a89f682c..16e5014de 100644 --- a/src/module-elasticsuite-core/etc/adminhtml/system.xml +++ b/src/module-elasticsuite-core/etc/adminhtml/system.xml @@ -66,6 +66,11 @@ In seconds. validate-number + + + In seconds. + validate-number +