Async support for elasticsearch-php
- Unsupported
ping
method - Unsupported
exists
method - Unsupported logging
{
"require": {
"elasticsearch/elasticsearch": "~1.0",
"iwai/elasticsearch-guzzle5connection": "~1.0"
}
}
use Elasticsearch\Client as ESClient;
$client = new ESClient([
'hosts' => [ '127.0.0.1:9200' ],
'connectionClass' => '\Iwai\Elasticsearch\Guzzle5Connection',
'serializerClass' => '\Iwai\Elasticsearch\FutureSerializer'
]);
$response = $client->get([
'index' => 'index_name',
'type' => 'type',
'id' => '1',
]);
echo $response['hits']['total'];
use Elasticsearch\Client as ESClient;
$client = new ESClient([
'hosts' => [ '127.0.0.1:9200' ],
'connectionClass' => '\Iwai\Elasticsearch\Guzzle5Connection',
'serializerClass' => '\Iwai\Elasticsearch\FutureSerializer'
]);
$future = $client->get([
'index' => 'index_name',
'type' => 'type',
'id' => '1',
]);
$response = $future->wait();
echo $response['hits']['total'];
use Elasticsearch\Client as ESClient;
$client = new ESClient([
'hosts' => [ '127.0.0.1:9200' ],
'connectionClass' => '\Iwai\Elasticsearch\Guzzle5Connection',
'serializerClass' => '\Iwai\Elasticsearch\FutureSerializer'
]);
$future = $client->get([
'index' => 'index_name',
'type' => 'type',
'id' => '1',
]);
$futureData->then(function ($response) {
echo $response['hits']['total'];
});
use React\EventLoop;
use WyriHaximus\React\RingPHP\HttpClientAdapter;
use Elasticsearch\Client as ESClient;
$loop = EventLoop\Factory::create();
$client = new ESClient([
'hosts' => [ '127.0.0.1:9200' ],
'connectionClass' => '\Iwai\Elasticsearch\Guzzle5Connection', // required
'serializerClass' => '\Iwai\Elasticsearch\FutureSerializer', // required
'connectionParams' => [ 'ringphp_handler' => new HttpClientAdapter($loop) ] // optional
]);
$futureData = $client->get([
'index' => 'index_name',
'type' => 'type',
'id' => '1',
]);
$futureData->then(function ($response) {
echo $response['hits']['total'];
});
$loop->run();