Skip to content

A wrapper around the elasticsearch module to provide promise based workflow and a readable syntax.

License

Notifications You must be signed in to change notification settings

FronterAS/elasticsearch-wrapper

Repository files navigation

elasticsearch-wrapper Build Status

A wrapper around the elasticsearch module to provide promise based workflow and a readable syntax.

Getting started

Add the dependency to your package.json

"dependencies": {
  "elasticsearch-wrapper": "git://github.com/FronterAS/elasticsearch-wrapper.git#tag"
}

Usage

To use the wrapper, you first need to setup the config parameters, which at its barest requires a URL to the ElasticSearch instance.

var DB = require('elasticsearch-wrapper');

DB.config({
    db: {
        url: 'http://localhost:9200'
    }
});

The ElasticSearch wrapper depends heavily on chaining method calls to perform actions with the last method (which performs the actual action) returning a promise.

var query = { match: { body: 'test' } },
    filter = { term: { user: 1337 } };

// Query for articles filtered by user
DB.query(query).ofType('article').filterBy(filter).from('my_index')
    .done(function (response) {
        console.log('Fetched ' + response.results.length + ' articles');
    }, function (response) {
        console.log('ElasticSearch Error: ' + response.error.message);
    });

Testing

# Install the grunt-cli global node module
sudo npm install -g grunt-cli

# Install all the development dependencies
npm install

First, duplicate the test/config.json.example file and make relevant changes that apply to your system.

cp config.js.example config.js
grunt test

This will run jshint, mocha and blanket for code coverage.

Jshint can be run separately using

grunt jshint

as can blanketjs coverage generation.

grunt coverage

About

A wrapper around the elasticsearch module to provide promise based workflow and a readable syntax.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •