The openseach-php library removes the hard-coded dependency on the Guzzle HTTP client and switches to the following PSR interfaces:
You can continue to use Guzzle, but will need to configure it as a PSR-18 HTTP Client.
Starting with opensearch-php 2.4.0 you can use any PSR-18 compatible HTTP client.
To simplify creating a Client, we provide two factories to create PSR-18 HTTP clients for Guzzle and Symfony HTTP clients since opensearch-php 2.5.0.
To configure Guzzle as a PSR HTTP Client with the similar configuration to opensearch-php 1.x you can use the following example:
Ensure the Guzzle packages are installed via composer:
composer require guzzlehttp/guzzle
$client = (new \OpenSearch\GuzzleClientFactory())->create([
'base_uri' => 'https://localhost:9200',
'auth' => ['admin', getenv('OPENSEARCH_PASSWORD')],
'verify' => false,
]);
// Send a request to the 'info' endpoint.
$info = $client->info();
You can configure Symfony HTTP Client as a PSR HTTP Client using the following example:
composer require symfony/http-client
$client = (new \OpenSearch\SymfonyClientFactory())->create([
'base_uri' => 'https://localhost:9200',
'auth_basic' => ['admin', getenv('OPENSEARCH_PASSWORD')],
'verify_peer' => false,
]);
// Send a request to the 'info' endpoint.
$info = $client->info();