Commit e985e680 authored by Son Nguyen's avatar Son Nguyen
Browse files

Improve the indexing for elasticsearch plugin. Bug 1421033



Time of indexing reduces from 2 hours to 23m on my dev machine after
applying this patch

Change-Id: Ia827a0c3945509e388da516109397a3db6e29eca
Signed-off-by: default avatarSon Nguyen <son.nguyen@catalyst.net.nz>
parent b93f7212
......@@ -570,6 +570,7 @@ class PluginSearchElasticsearch extends PluginSearch {
$artefacttypesmap_array = self::elasticsearchartefacttypesmap_to_array();
$documents = array();
foreach ($records as $record) {
$deleteitem = false;
$tmp = null;
......@@ -594,14 +595,18 @@ class PluginSearchElasticsearch extends PluginSearch {
if ($deleteitem == true) {
$tmp = $elasticaClient->deleteIds(array($record->itemid), $indexname, $record->type);
}
// Index item
// Add item for bulk index
else {
$elasticaType = $elasticaIndex->getType($record->type);
$doc = new \Elastica\Document($record->itemid, $item->getMapping());
$elasticaType->addDocument($doc);
$documents[$record->type][] = new \Elastica\Document($record->itemid, $item->getMapping());
}
delete_records('search_elasticsearch_queue', 'id', $record->id);
}
// Bulk index
foreach ($documents as $type => $docs) {
$elasticaType = $elasticaIndex->getType($type);
$elasticaType->addDocuments($docs);
}
// Refresh Index
$elasticaIndex->refresh();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment