简体   繁体   English

Elasticsearch 2 + PHP 滚动流问题

[英]Elasticsearch 2 + PHP scroll flow issue

Hi can somebody tell me please how to execute scroll on Elasticsearch 2 via PHP Ruflin\\Elastica library?嗨,有人能告诉我如何通过 PHP Ruflin\\Elastica 库在 Elasticsearch 2 上执行滚动吗? According documentation for ES2 first scroll request should lead to specific index while next requests are called without index with only scroll_id parameter.根据 ES2 的文档,第一个滚动请求应该导致特定的索引,而下一个请求在没有索引的情况下仅使用 scroll_id 参数调用。 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?第二次调用 Elasticsearch 有什么问题? Why it throws error: No enabled connection?为什么会抛出错误:没有启用的连接? Hope somebody knows cause I really dont.希望有人知道,因为我真的不知道。

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 connection 1 . Elastica\\Client默认使用循环连接池来解决连接问题,如果所有连接都消失了,它会抛出ClientException并带有消息No enabled connection 1

Check your network connectivity between PHP script and Elasticsearch and review your configuration for Elasticsearch.检查 PHP 脚本和 Elasticsearch 之间的网络连接并检查 Elasticsearch 的配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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