waterline-elasticsearch

0.1.3 • Public • Published

image_squidhome@2x.png

waterline-elasticsearch

Provides easy access to elasticsearch from Sails.js & Waterline.

Installation

To install this adapter, run:

$ npm install waterline-elasticsearch

Configuration

var orm = new Waterline();
 
var config = {
    adapters: {
        elasticsearch: require('waterline-elasticsearch')
    },
    connections: {
        myLocalElasticsearch: {
            adapter: 'elasticsearch',
            host: 'localhost',
            port: 9200,
            log: 'warning',
            index: '<index to use>'
        }
    }
};
 

Usage

var createModel = function(orm, identity, connection, tablename) {
    console.log("Using connection: " + connection + " for object: " + identity);
    var obj = Waterline.Collection.extend({
        identity: identity,
        tableName: tablename ? tablename : identity + 's',
        connection: connection,
        attributes: {
            id: {
                type: 'integer',
                primaryKey: true,
                // required: true,
                index: true
            }
        }
    });
    orm.loadCollection(obj);
}
 
createModel(orm, 'note', 'myLocalElasticsearch', 'notes');
 
orm.initialize(config, function(err, models) {
    if (err) throw err;
    app.models = models.collections;
});
 
app.models[note].findOne({
    id: id
}).exec(function(err, model) {
    if (err) console.log(err);
    console.log(model);
});
 

This adapter exposes the following methods:

find()
  • Status
    • Done
findOne()
  • Status
    • Done
create()
  • Status
    • Done
update()
  • Status
    • Done
destroy()
  • Status
    • Done

Package Sidebar

Install

npm i waterline-elasticsearch

Weekly Downloads

0

Version

0.1.3

License

MIT

Last publish

Collaborators

  • sspilleman