iwai/elasticsearch-guzzle5connection

There is no license information available for the latest version (1.0.1) of this package.

1.0.1 2015-05-26 11:35 UTC

This package is not auto-updated.

Last update: 2024-11-19 09:44:06 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License Build Status

Async support for elasticsearch-php

Caution!!!

  • Unsupported ping method
  • Unsupported exists method
  • Unsupported logging

Install

{
    "require": {
        "elasticsearch/elasticsearch": "~1.0",
        "iwai/elasticsearch-guzzle5connection": "~1.0"
    }
}

Example

Transparent async request

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'];

Explicit wait request

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'];

Promise style

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'];
});

With RingPHP

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();