Client is not supported for custom options
Asked Answered
E

1

3

I am trying to use ClientBuilder of Elasticsearch using symfony 6. I am getting following error

The HTTP client Symfony\Component\HttpClient\Psr18Client is not supported for custom options

This is the code I have tried. I had same lines of code in laravel which worked.

$hosts = ['https://localhost:9200'];
$client = ClientBuilder::create()
    ->setHosts($hosts)
    ->setSSLVerification(false)
    ->setBasicAuthentication('elastic', 'password')
    ->build();
Enenstein answered 5/4, 2022 at 8:2 Comment(0)
V
5

Just ran into the same issue in a Laravel 9 app (along with some other bugs in the package).

Be sure to set the client manually, otherwise it uses \Http\Discovery\Psr18ClientDiscovery to find the first class that extends the required interface \Psr\Http\Client\ClientInterface. Which in our case is Symfony\Component\HttpClient\Psr18Client, which is not yet supported (see 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();
Viol answered 5/4, 2022 at 15:26 Comment(3)
How to set the ClientBuilder::create manually?Enenstein
$clientBuilder is identical to ClientBuilder::create(). Edited my answer, can't reply properly here.Viol
If you get a CURL SSL self signed error, add: new \GuzzleHttp\Client([ 'verify' => false, ]Confirmand

© 2022 - 2024 — McMap. All rights reserved.