README
mongodb-elasticsearch-river
Tool to index MongoDB documents using Elasticsearch
require("mongodb-elasticsearch-river")
Methods
next(opts) - Build function to handle "next" event
@param {object} opts - Describes configuration
@param {object} opts.client - Elasticsearch client
@param {object} opts.emitter - Instance of EventEmitter
@param {index} opts.index - Index
@param {boolean} [opts.parse] - Parse next value, if function should receive stringified document instead of MongoDB oplog document
@returns {next} - Function to handle "next" event
init(opts, [cb]) - Initially import MongoDB documents, by default using index.namespace.collection
@param {object} opts - Describes configuration
@param {object} opts.client - Elasticsearch client
@param {function} opts.Timestamp - MongoDB Timestamp constructor - mongodb.Timestamp || bson.Timestamp
@param {index} opts.index - Index
@param {object} [opts.query = {}] - MongoDB query, if use collection to import
@param {object} [opts.oplog] - MongoDB oplog.rs collection, use it to import
@param {number} [opts.time] - Number of milliseconds, if use oplog.rs to import
@param {callback} [cb] - Callback
@returns {object} promise - Instance of Promise, if callback not defined
Type Definitions
namespace - Describes MongoDB namespace - 'db.collection'
@typedef {string} namespace
index - Describes configuration to build index
@typedef {object} index
@property {object} index.namespace - MongoDB namespace - 'db.collection'
@property {string} [index.namespace.index] - Elasticsearch index
@property {string} [index.namespace.type] - Elasticsearch type
@property {string[] | string} [index.namespace.fields] - MongoDB documents fields to index
@property {object} [index.namespace.collection] - MongoDB collection to initially import MongoDB documents or to update index using collection
@property {serialize} [index.namespace.serialize] - Function to serialize MongoDB document
@property {boolean} [index.namespace.script] - Update index using Elasticsearch scripting
serialize - Function to serialize MongoDB document
@typedef {function} serialize
@param {object} obj - MongoDB document
@returns {object} - MongoDB document
next - Function to handle "next" event, does index MongoDB document, fires "error" event on error, fires "success" event on index success
@typedef {function} next
@param {object | string} item - MongoDB oplog document || stringified document
callback
@callback callback
@param {object} err - Instance of Error
Examples
- run river, update index using index.namespace.collection
- run river, update index using Elasticsearch scripting
- initially import MongoDB documents using index.namespace.collection
- initially import MongoDB documents using index.namespace.collection with specified MongoDB query
- initially import MongoDB documents not imported yet using MongoDB oplog.rs collection
- initially import MongoDB documents which have been updated for specified time using MongoDB oplog.rs collections