K
K
kolya_krut2017-02-10 12:10:39
PHP
kolya_krut, 2017-02-10 12:10:39

How to wait for all queries to complete in Elasticsearch?

Hello.
I'll forgive my nubism, but I can't figure out the subject.
In the php script, you need to execute the bulk request and wait until it is all completed. To work with ES, their official lib is used. As I understood from the docks, you can use Future Mode for a solution . But it is not possible to apply it correctly. I use like this:

// вызов функций одну за другой
func_bulk();
func_search();

// выполнение запроса
function func_bulk()
{
    $params['client'] = [
        'future' => 'lazy'
    ];
    $response = $this->elastic->bulk($params);
    while ($response instanceof FutureArray) {
        $response = $response->wait();
    }
}

// поиск того, что сделано в func_bulk()
function func_search()
{
    $params = [
        'index' => 'my_index',
        'type' => 'my_type',
        'id' => 'my_id'
    ];
    $response = $client->get($params);
}

func_search()finds nothing, because Documents have not yet been indexed. If you insert a sticky type before the function sleep(5), it finds everything, but this is not serious. How can you wait until ES finishes its business?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
un1t, 2017-02-10
@un1t

https://www.elastic.co/guide/en/elasticsearch/refe...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question