Tasks
Learn how to work with asynchronous Elasticsearch operations to process documents in a non-blocking manner
var oldIndex = "books_v1";
var newIndex = "books_v2";
var reindexTask = getInstance( "Client@cbelasticsearch" )
.reindex(
source = oldIndex,
destination = newIndex,
waitForCompletion = false,
params = {
// throttle our reindexing tasks to ensure we don't kill the ES server on a big index - https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html#docs-reindex-throttle
"requests_per_second" : 50,
// slice the reindex to concurrent 5 batches at a time - https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html#docs-reindex-automatic-slice
"slices" : 5
}
);
while( !reindexTask.isComplete() ){
var status = reindexTask.getStatus();
writeOutput( "Waiting for task to complete. #status.created# documents of #status.total# documents have been migrated to #newIndex#" );
flush();
}Last updated
Was this helpful?