All files / src/controllers bulk.js

100% Statements 9/9
0% Branches 0/4
100% Functions 7/7
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 751x       107x                           1x               1x                             1x             1x                           1x           1x         1x  
const BaseController = require('./base');
 
class BulkController extends BaseController {
  constructor (kuzzle) {
    super(kuzzle, 'bulk');
  }
 
  /**
   * Creates, updates or deletes large amounts of documents as fast as possible.
   * {@link https://docs.kuzzle.io/core/1/api/controllers/bulk/import/|Official documentation}
   *
   * @param {String} index - Index name
   * @param {String} collection - Collection name
   * @param {Object[]} bulkData - Array of documents detailing the bulk operations to perform, following ElasticSearch Bulk API
   * @param {Object} [options] - Additional options
   * @returns {Promise}
   */
  import (index, collection, bulkData, options = {}) {
    return this.query({
      index,
      collection,
      action: 'import',
      body: {
        bulkData
      }
    }, options)
      .then(response => response.result);
  }
 
  /**
   * Creates or replaces a document directly into the storage engine.
   * {@link https://docs.kuzzle.io/core/1/api/controllers/bulk/write/|Official documentation}
   *
   * @param {String} index - Index name
   * @param {String} collection - Collection name
   * @param {Object} document - Document body
   * @param {String} [id=null] - Document ID
   * @param {Object} [options] - Additional options (notify, refresh)
   * @returns {Promise}
   */
  write (index, collection, document, id = null, options = {}) {
    return this.query({
      index,
      collection,
      _id: id,
      action: 'write',
      body: document
    }, options)
      .then(response => response.result);
  }
 
  /**
   * Creates or replaces multiple documents directly into the storage engine.
   * {@link https://docs.kuzzle.io/core/1/api/controllers/bulk/m-write/|Official documentation}
   *
   * @param {String} index - Index name
   * @param {String} collection - Collection name
   * @param {Object[]} documents - Array of objects describing the documents with '_id' and '_source' properties
   * @param {Object} [options] - Additional options (notify, refresh)
   * @returns {Promise}
   */
  mWrite (index, collection, documents, options = {}) {
    return this.query({
      index,
      collection,
      action: 'mWrite',
      body: { documents }
    }, options)
      .then(response => response.result);
  }
 
}
 
module.exports = BulkController;