
Elastic::Model::Bulk - Bulk-saving of multiple docs for increased throughput

version 0.26

$bulk = $model->bulk(
size => 1000,
on_conflict => sub {...},
on_error => sub {...}
);
$bulk->save($doc);
$bulk->overwrite($doc);
...
$bulk->commit;

If you need to create or update multiple docs at once, then bulk indexing is the way to go. It batches up the documents and saves size (default 1000) documents in a single request, which is much faster than writing each doc individually.
Once you are finished adding docs to the $bulk indexer, call "commit()" to save any docs that haven't been saved yet. If $bulk goes out of scope, then "commit()" will be called for you, but it is safer to call it yourself.
Note: Bulk indexing is not supported for classes which have unique key constraints.

The number of docs that will be saved in a single request. Defaults to 1000.
A callback which will be called if there is any conflict when saving a doc, for instance, trying to create a doc that already exists, or trying to save a doc when a newer version already exists in Elasticsearch.
The callback is called with two arguments:
See "save()" in Elastic::Model::Role::Doc for more.
The on_error callback will be called for any non-conflict error (or for conflict errors if no "on_conflict" handler has been specified). It is called with two arguments:
If no on_error handler is specified, then bulk indexing will die with an error message.

$bulk->save($doc);
Adds a doc to the internal queue to be saved later.
$bulk->overwrite($doc);
Adds a doc to the interal queue to be overwritten later. In other words, no version checking is done - if a newer version of the doc exists in Elasticsearch, it will be overwritten.
$bulk->commit()
Writes all docs in the queue to Elasticsearch. This is called automatically when there are "size" docs in the queue, or when the $bulk instance goes out of scope, although you should call "commit()" yourself once you are finished adding docs, just to be on the safe side.
$bulk->clear()
Clears any docs that are still in the queue.

Clinton Gormley <drtech@cpan.org>

This software is copyright (c) 2013 by Clinton Gormley.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.