【问题标题】:PHP Ruflin/Elastica - how to refresh index on huge data insertPHP Ruflin/Elastica - 如何在大量数据插入时刷新索引
【发布时间】:2019-03-16 21:48:00
【问题描述】:

我需要向 Elasticsearch 数据库中插入大约 150 万个文档。我通过 PHP 库 Elastica 根据this example (BULK example)

做到这一点

我想知道是否可以在批量插入的最后使用 call $elasticaType->getIndex()->refresh(); 命令,以及它是否比在每次批量发送后调用 $elasticaType->getIndex()->refresh(); 更安全、更快。 我的意思是这样的:

$offset = 0;
$limit = 500;
$sum = 1500000,

while( $offset < $sum )
{        
    $documents = [];
    $rows = $sqlDatabase->getData( $offset, $limit )

    foreach( $rows as $row )
    {
        $docData = ['name' => $row->name, 'email' => $row->email]
        $documents[] = new \Elastica\Document( $data->id, $docData );
    }

    $elasticaType->addDocuments( $documents );
    $offset += 500;
    // Source example has refresh here. After every 500 items. But I wont it at the very end of the code after all 1500000 item are in the database.
    // $elasticaType->getIndex()->refresh();
}

$elasticaType->getIndex()->refresh();  // This is what I want.

是否可以在elasticsearch中插入1500000个文档,然后调用$elasticaType-&gt;getIndex()-&gt;refresh();

【问题讨论】:

  • 您尝试过这样做吗?怎么了?
  • 不,我没有。我现在就做。我不知道会发生什么。
  • 文档说建议的散装物品数量​​约为 500,我不知道它是否也与刷新调用有关。
  • 它说 500 是一个好的开始。您的服务器功率和您愿意等待多长时间是您的主要考虑因素。所以基本上你必须测试一下看看。
  • 我在本地主机上做。所以每次批量刷新大约需要 3.5 小时。

标签: php elasticsearch indexing elastica


【解决方案1】:

是否可以将1500000个文档插入elasticsearch然后 调用 $elasticaType->getIndex()->refresh();?

绝对是的。

refresh 使您的文档可用于搜索,该机制源自 Apache Lucene 以提供近实时 (NRT) 搜索功能,它使用 DirectoryReader.openIfChanged 重新打开索引。

通常您不必自己做,定期安排刷新 默认情况下,您可以将 refresh_interval 的值更改为更短的 NRT 搜索时间,或更长的性能。

【讨论】:

  • 是的,我写的是 12.10.2018
猜你喜欢
  • 1970-01-01
  • 2017-08-30
  • 1970-01-01
  • 2011-06-22
  • 2018-01-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-01
相关资源
最近更新 更多