diff --git a/docs/reference/node_pool.md b/docs/reference/node_pool.md index 7c53b6a1a..b1839871c 100644 --- a/docs/reference/node_pool.md +++ b/docs/reference/node_pool.md @@ -47,6 +47,10 @@ $transport = TransportBuilder::create() ### Using a custom NodePool, Selector and Resurrect [_using_a_custom_nodepool_selector_and_resurrect] +::::{note} +The Elasticsearch PHP client can be used to connect to on-premises, Elastic Cloud, or Serverless deployments. When using Elastic Cloud or Serverless, there is no need to configure a custom NodePool — the default one is sufficient. +:::: + If you want you can implement your custom node pool algorithm. We provided a [NodePoolInterface](https://github.com/elastic/elastic-transport-php/blob/master/src/NodePool/NodePoolInterface.php) You can also customize the Selector and the Resurrect components of the node pool. You can use the following interfaces for the implementation: diff --git a/src/Transport/Adapter/Guzzle.php b/src/Transport/Adapter/Guzzle.php index dfacc97fe..7df3f7c19 100644 --- a/src/Transport/Adapter/Guzzle.php +++ b/src/Transport/Adapter/Guzzle.php @@ -15,6 +15,7 @@ namespace Elastic\Elasticsearch\Transport\Adapter; use Elastic\Elasticsearch\Transport\RequestOptions; +use GuzzleHttp\Client; use GuzzleHttp\RequestOptions As GuzzleOptions; use Psr\Http\Client\ClientInterface; @@ -38,7 +39,13 @@ public function setConfig(ClientInterface $client, array $config, array $clientO $guzzleConfig[GuzzleOptions::VERIFY] = $value; } } + /** @var Client $client */ + if(method_exists($client, 'getConfig')){ + $clientOptions = array_merge($clientOptions, $client->getConfig()); + } + $class = get_class($client); + return new $class(array_merge($clientOptions, $guzzleConfig)); } } \ No newline at end of file diff --git a/tests/Transport/Adapter/GuzzleTest.php b/tests/Transport/Adapter/GuzzleTest.php index fec894d03..5e8fd3788 100644 --- a/tests/Transport/Adapter/GuzzleTest.php +++ b/tests/Transport/Adapter/GuzzleTest.php @@ -17,6 +17,7 @@ use Elastic\Elasticsearch\Transport\Adapter\Guzzle; use Elastic\Elasticsearch\Transport\RequestOptions; use GuzzleHttp\Client; +use GuzzleHttp\HandlerStack; use GuzzleHttp\RequestOptions As GuzzleOptions; use PHPUnit\Framework\TestCase; use Psr\Http\Client\ClientInterface; @@ -65,4 +66,11 @@ public function testSetConfigWithSslCa() $this->assertInstanceOf(Client::class, $result); $this->assertEquals('test', $result->getConfig(GuzzleOptions::VERIFY)); } + + public function testSetConfigButNotOverwrittenClientOptions() + { + $result = $this->guzzleAdapter->setConfig(new Client(['base_uri' => 'http://localhost:12345']), [ RequestOptions::SSL_CA => 'test'], []); + $this->assertInstanceOf(Client::class, $result); + $this->assertEquals('http://localhost:12345', $result->getConfig('base_uri')); + } } \ No newline at end of file