e3po

Module to index and search MongoDB documents using Elasticsearch

e3po

Module to index and search MongoDB documents using Elasticsearch

require("e3po")

e3po factory

require("e3po")(opts)
@param {Object} opts
@param {Object} opts.client - Elasticsearch client
@param {string} opts.index - Elasticsearch index
@param {string} opts.type - Elasticsearch type
@returns {e3po}

e3po

@typedef {Object} e3po
@property {find} find - Search using MongoDB query
@property {search} search - Search using Elasticsearch query
@property {upsert} upsert - Create or update index
@property {remove} remove - Remove index
@property {update} update - Update index
@property {updateByScript} updateByScript - Update index using groovy script and MongoDB update query
@property {updateByQuery} updateByQuery - Update index by query using groovy script, MongoDB query and MongoDB update query
@property {removeByQuery} removeByQuery - Remove index by query using MongoDB query

e3po.find - Search using MongoDB query

@typedef {function} find
@param {Object} [opts]
@param {mongodbQuery} [opts.query = {}]
@param {mongodbQuery} [opts.filter]
@param {Object} [opts.sort]
@param {number} [opts.skip]
@param {number} [opts.limit]
@param {Object} [opts.projection]
@param {Object} [params = {}]
@returns {Object} Instance of Promise

e3po.search - Search using Elasticsearch query

@typedef {function} search
@param {Object} [opts]
@param {elasticsearchQuery} [opts.query = { match_all: {} }]
@param {Object} [opts.sort]
@param {number} [opts.skip]
@param {number} [opts.limit]
@param {Object} [opts.projection]
@param {Object} [params = {}]
@returns {Object} Instance of Promise

e3po.upsert - Create or update index

@typedef {function} upsert
@param {Object} opts
@param {ObjectId|string} [opts.id]
@param {Object} opts.body - body to index
@param {Object} [params = {}]
@param {string} [params.refresh] - 'true' || 'false' || 'wait_for'
@returns {Object} Instance of Promise

e3po.remove - Remove index

@typedef {function} remove
@param {Object} opts
@param {ObjectId|string} opts.id
@param {Object} [params = {}]
@returns {Object} Instance of Promise

e3po.update - Update index

@typedef {function} update
@param {Object} opts
@param {ObjectId|string} opts.id
@param {Object} opts.body - body to merge with indexed body
@param {Object} [params = {}]
@param {string} [params.refresh] - 'true' || 'false' || 'wait_for'
@param {number} [params.retryOnConflict]
@returns {Object} Instance of Promise

e3po.updateByScript - Update index using groovy script and MongoDB update query

@typedef {function} updateByScript
@param {Object} opts
@param {ObjectId|string} opts.id
@param {mongodbUpdateQuery} opts.body
@param {Object} [params = {}]
@param {string} [params.refresh] - 'true' || 'false' || 'wait_for'
@param {number} [params.retryOnConflict]
@returns {Object} Instance of Promise

e3po.updateByQuery - Update index by query using groovy script, MongoDB query and MongoDB update query

@typedef {function} updateByQuery
@param {Object} opts
@param {mongodbQuery} [opts.query = {}]
@param {mongodbQuery} [opts.filter]
@param {Object} [opts.sort]
@param {number} [opts.skip]
@param {number} [opts.limit]
@param {mongodbUpdateQuery} opts.body
@param {Object} [params = {}]
@param {boolean} [params.refresh]
@param {boolean} [params.waitForCompletion]
@param {string} [params.conflicts] - 'abort' || 'proceed'
@returns {Object} Instance of Promise

e3po.removeByQuery - Remove index by query using MongoDB query

@typedef {function} removeByQuery
@param {Object} [opts]
@param {mongodbQuery} [opts.query = {}]
@param {mongodbQuery} [opts.filter]
@param {Object} [opts.sort]
@param {number} [opts.skip]
@param {number} [opts.limit]
@param {Object} [params = {}]
@param {boolean} [params.refresh]
@param {boolean} [params.waitForCompletion]
@param {string} [params.conflicts] - 'abort' || 'proceed'
@returns {Object} Instance of Promise

Type definitions

  @typedef {Object} mongodbQuery
  @typedef {Object} elasticsearchQuery
  @typedef {Object} mongodbUpdateQuery
  @typedef {Object} ObjectId

Tests

  • set ELASTICSEARCH_HOST, ELASTICSEARCH_PORT, ELASTICSEARCH_INDEX and ELASTICSEARCH_TYPE environment variables
  • set script.engine.groovy.inline.update: true at elasticsearch.yml file
  • run npm test

Warning: pretest script removes ELASTICSEARCH_HOST:ELASTICSEARCH_PORT/ELASTICSEARCH_INDEX

Related Repositories

e3po

e3po

Module to index and search MongoDB documents using Elasticsearch ...