Add bulk indexing

This commit is contained in:
Mathieu Darse
2014-08-26 19:22:28 +02:00
parent 7db59052d6
commit 2d4decbf65
2 changed files with 91 additions and 3 deletions

View File

@@ -78,19 +78,24 @@ class Indexer
$this->disableShardRefreshing();
try {
// Prepare the bulk operation
$bulk = new BulkOperation($this->client);
$bulk->setDefaultIndex($this->options['index']);
$bulk->setDefaultType(self::RECORD_TYPE);
$bulk->setAutoFlushLimit(1000);
foreach ($this->appbox->get_databoxes() as $databox) {
$fetcher = new RecordFetcher($databox);
$fetcher->setBatchSize(200);
while ($record = $fetcher->fetch()) {
$params = array();
$params['index'] = $this->options['index'];
$params['type'] = self::RECORD_TYPE;
$params['id'] = $record['id'];
$params['body'] = $record;
$response = $this->client->index($params);
$bulk->index($params);
}
}
$bulk->flush();
// Optimize index
$params = array('index' => $this->options['index']);
$this->client->indices()->optimize($params);