From 2407a37dbbcbd33bba4325fabb8b8f962a7cb6c7 Mon Sep 17 00:00:00 2001 From: Pius Fung Date: Wed, 17 Sep 2025 22:14:50 -0700 Subject: [PATCH 1/2] Update node_pool.md with Elasticsearch PHP client note Clarified that custom NodePool is not necessary for connecting to Elastic Cloud Hosted or Serverless. --- docs/reference/node_pool.md | 4 ++++ 1 file changed, 4 insertions(+) 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: From 8e98d06508cc6ce143fe1efbc01241ff05266243 Mon Sep 17 00:00:00 2001 From: minororange Date: Thu, 25 Sep 2025 19:53:18 +0800 Subject: [PATCH 2/2] fix: Custom Guzzle/Client Configuration Has Been Overwritten tests: add test unit --- src/Transport/Adapter/Guzzle.php | 7 +++++++ tests/Transport/Adapter/GuzzleTest.php | 8 ++++++++ 2 files changed, 15 insertions(+) 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