store-elastic

The ElasticSearch store is a wrapper over elasticsearch that provides a small abstraction layer between your application and ElasticSearch. It is currently under development and features will be added in the future. For the full API documentation, visit the official docs

Installation and usage
npm i --save thorin-store-elastic@1.x
'use strict';
// app.js entry file
const thorin = require('thorin');

thorin.addStore(require('thorin-store-elastic'));   // <- add this line
thorin.run((err) => {});

# run to setup the database and module
node app.js --setup=store.elastic
Default configuration
  • debugtrueif set to false, disables debugging completely. Can also be an object (see below)
  • debug.createtrue enable debugging for document creation
  • debug.readtrue enables debugging for document retrievals
  • debug.updatetrue enables debugging for document updates
  • debug.deletetrue enables debugging for document removals
  • clients['http://localhost:9200'] an array of ElasticSearch clients to connect to. Can also use array of client objects (see docs)
  • headersnullan object containing key-value HTTP Headers to send on each request.
  • usernamenullthe store username to use together with password, for basic auth
  • passwordnullthe store password used for basic auth
  • optionsdefault options additional ElasticSearch options.
Store functionality
storeObj.client
Expose the actual ElasticSearch client connection for manual querying.
storeObj.createIndex(name, opt) : Promise
Creates a new index with the given name and options.
storeObj.deleteIndex(name) : Promise
Deletes the given index by its name.
storeObj.existsIndex(name, opt)
Verifies if the given index name exists
storeObj.getIndexes(opt) : array(string)
Returns an array of index names that exist in the store.
storeObj.getIndex(name) : ESIndex
Returns the information of an index, wrapped inside an ESIndex object
ESIndex class

The ESIndex class is offers specific functionality to manage index-specific actions.

create(type, data, opt) : Promise
Creates a new document inside the current index, giving it the specified type and associated data.
  • typestring the document type
  • dataobject the associated document data
  • optobject additional create options found in the ES docs.
createBulk(type, items, opt) : Promise
Performs a bulk insert of documents with the given type. Items is an array of data objects associated for each document that should be created.
  • typestring the document types
  • itemsarray(object) an array with objects containing the data we want to insert.
  • optobject additional create options found in the ES docs.
find(type, query, raw) : Promise
Finds a single document filtered by its type and search query
  • typestring the document type
  • queryobjectthe query to apply
  • rawboolean, falseuse raw ElasticSearch query and not store-processed query
count(type, query, raw) : Promise
Returns the number of documents matching the given type and query
  • typestring the document type
  • queryobjectthe query to apply
  • rawboolean, falseuse raw ElasticSearch query and not store-processed query
findAll(type, query, raw) : Promise
Returns all the documents that match the given type and search query.
  • typestring the document type
  • queryobjectthe query to apply
  • rawboolean, falseuse raw ElasticSearch query and not store-processed query
update(type, id, data, opt) : Promise
Updates the document of the given type and id, with the given data.
  • typestring the document type
  • idstringthe document id
  • dataobjectobject containing the fields we want to update.
  • optobject additional ES options, see docs.
destroy(type, id) : Promise
Destroys the document of the given type and id
  • typestring the document type
  • idstringthe document id
Do you have a question or is something missing?

You can always create a new issue on GitHub or contact one of the core founders by chat.