View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Clinton Gormley > Elastic-Model > Elastic::Model::Bulk



Annotate this POD

View/Report Bugs
Module Version: 0.52   Source  


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


version 0.52


    $bulk = $model->bulk(
        size        => 1000,
        on_conflict => sub {...},
        on_error    => sub {...}




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.


An optional callback which will be called when a document has been indexed successfully. It is called with a single argument: the current document.


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.




Adds a doc to the internal queue to be saved later.



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.



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.



Clears any docs that are still in the queue.


Clinton Gormley <>


This software is copyright (c) 2015 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.

syntax highlighting: