客户端不支持自定义选项

nas*_*nas 3 php symfony6

我正在尝试使用ClientBuildersymfony 6 来使用 Elasticsearch。我收到以下错误

The HTTP client Symfony\Component\HttpClient\Psr18Client is not supported for custom options
Run Code Online (Sandbox Code Playgroud)

这是我尝试过的代码。我在 laravel 中也有同样有效的代码行。

$hosts = ['https://localhost:9200'];
$client = ClientBuilder::create()
    ->setHosts($hosts)
    ->setSSLVerification(false)
    ->setBasicAuthentication('elastic', 'password')
    ->build();
Run Code Online (Sandbox Code Playgroud)

Seb*_*uca 5

刚刚在 Laravel 9 应用程序中遇到了同样的问题(以及包中的一些其他错误)。

请务必手动设置客户端,否则它将用于\Http\Discovery\Psr18ClientDiscovery查找扩展所需接口的第一个类\Psr\Http\Client\ClientInterface。在我们的例子中是Symfony\Component\HttpClient\Psr18Client,尚不支持(请参阅https://github.com/elastic/elasticsearch-php/issues/990)。

$hosts = ['https://localhost:9200'];

$client = ClientBuilder::create()
    ->setHttpClient(new \GuzzleHttp\Client)
    ->setHosts($hosts)
    ->setSSLVerification(false)
    ->setBasicAuthentication('elastic', 'password')
    ->build();
Run Code Online (Sandbox Code Playgroud)