1

Hi can somebody tell me please how to execute scroll on Elasticsearch 2 via PHP Ruflin\Elastica library? According documentation for ES2 first scroll request should lead to specific index while next requests are called without index with only scroll_id parameter. So I wrote this code:

/** @var Elastica\Client $elastic */
$elastic = $container->getService( 'elastica' );

// This first call works fine. I get the scroll_id.
$elasticScrollData = $elastic->getIndex( 'event' )->request( '_search?scroll=5m', 'GET', ['size' => 500, 'sort' => ['_doc']] )->getData();

$countAll = $elasticScrollData['hits']['total'];

saveToMongo( $elasticScrollData, $countAll, $elastic );


function saveToMongo( $scrollData, $countAll, \Elastica\Client $elastic )
{
    $documents = [];
    foreach ( $scrollData['hits']['hits'] as $item )
    {
        $doc = [];
        $doc['ico'] = (array)$item['_source']['ico'];
        ...         

        $documents[] = $doc;
    }

    try
    {
        saveDataToDb( $documents );
    }
    catch( \Exception $e )
    {
        echo '+++ insert exception: ' . $e->getMessage() . "\n";
    }

    // Here is the problem. It throws me an exception: No enabled connection
    $scrollData = $elastic->request( '_search/scroll', 'GET', ['scroll' => '5m', 'scroll_id' => $scrollData['_scroll_id']] )->getData();

    saveToMongo( $scrollData, $countAll, $offset, $elastic, $mongoCollection );
}

What is wrong with the second call to Elasticsearch? Why it throws error: No enabled connection? Hope somebody knows cause I really dont.

1 Answer 1

1

The Elastica\Client use a round-robin connection pool by default to resolve connectivity issue, If all connections are gone, It throw ClientException with message No enabled connection1.

Check your network connectivity between PHP script and Elasticsearch and review your configuration for Elasticsearch.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes thats it. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.