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();
nas
  • 2,289
  • 5
  • 32
  • 67

1 Answers1

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();
Sebastiaan Luca
  • 486
  • 1
  • 8
  • 9