php - PHP Ruflin/Elastica - 如何在大量数据插入时刷新索引
问题描述
我需要向 Elasticsearch 数据库中插入大约 150 万个文档。我根据这个例子(BULK 例子)通过 PHP 库 Elastica 来做
我想知道是否可以在批量插入的最后使用调用命令,以及它是否比每次批量发送后$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.
是否可以将 1500000 个文档插入到 elasticsearch 然后调用$elasticaType->getIndex()->refresh();
?
解决方案
是否可以将1500000个文档插入elasticsearch,然后调用$elasticaType->getIndex()->refresh();?
肯定是的。
刷新使您的文档可用于搜索,此机制源自 Apache Lucene,以提供近实时 (NRT) 搜索功能,它使用DirectoryReader.openIfChanged重新打开索引。
通常您不必自己做,默认情况下会定期安排刷新,您可以将refresh_interval的值更改为更短的 NRT 搜索时间,或更长的性能。
推荐阅读
- java - 在 JList 中显示对象的 ArrayList
- javascript - 使用fabric js canvas作为threejs 3d模型纹理
- image - 如何将 tensorflow2crop_and_resize 用于本地图像?
- r - 使用 purr 通过 tidygraph 将计算映射到不同的网络
- javascript - 使用 Express NodeJS 构建的 2 级嵌套对象 JSON
- python - 我的 tkinter 程序不显示按钮
- php - 非模型关系的客户端集合,当它是多守卫 laravel 时
- forms - 如何更改表单提交联系表单的文本颜色?
- javascript - 如何将对象暴露给给定的模式?
- algorithm - 是否有一种已知的算法可以通过数字比较来简化布尔表达式?