简体   繁体   中英

How to set a proxy in official Elasticsearch PHP client?

I know you can do it using the Elastica client like so:

$client = new \Elastica\Client(array(
    'host' => 'my host',
    'port' => '9200',
    'proxy' => 'my proxy'
));

but I'd like to use the official client if possible. I've set up a connection according to the documentation here .

$hosts = [
    [
    'host' => 'my host',
    'port' => '9200',
    'scheme' => 'http',
    'user' => 'my user',
    'pass' => 'my pass'
    ]
];
$client = Elasticsearch\ClientBuilder::create()
   ->setHosts($hosts)
   ->build();

However, there's nothing in the documentation on how to set a proxy. Is it possible?

BTW, I've seen this question , however it's outdated and doesn't work with the current version.

There may be a cleaner syntax, but setting cURL parameters should work:

$client = Elasticsearch\ClientBuilder::create()
   ->setHosts($hosts)
    ->setConnectionParams([
        'client' => [
            'curl' => [
                CURLOPT_PROXY => $proxy
            ]
        ]
    ])
   ->build();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM