【发布时间】: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->getIndex()->refresh();?
【问题讨论】:
-
您尝试过这样做吗?怎么了?
-
不,我没有。我现在就做。我不知道会发生什么。
-
文档说建议的散装物品数量约为 500,我不知道它是否也与刷新调用有关。
-
它说 500 是一个好的开始。您的服务器功率和您愿意等待多长时间是您的主要考虑因素。所以基本上你必须测试一下看看。
-
我在本地主机上做。所以每次批量刷新大约需要 3.5 小时。
标签: php elasticsearch indexing elastica