@skrumble/sails-elastic
Elasticsearch adapter for Sails / Waterline
Last updated 2 years ago by mdabydeen .
MIT · Repository · Original npm · Tarball · package.json
$ cnpm install @skrumble/sails-elastic 
SYNC missed versions from official npm registry.

waterline-elasticsearch

Join the chat at https://gitter.im/mie00/sails-elasticsearch

Installation

To install this adapter, run:

$ npm install sails-elastic

Configuration

config/connections.js

{
    adapter: 'sails-elastic',
    hosts: ['http://127.0.0.1:9200'],
    keepAlive: false,
    sniffOnStart: true,
    maxRetries: 10,
    deadTimeout: 40000,
    sniffOnConnectionFault: true,
    apiVersion: '5.5'
},

Models

Attributes

sails-elastic does not support attributes inside the model. It gets its attributes from another attribute in the model called elasticSearch. There you can tell elasticsearch how to create the index. You can find more information here.

// person model
module.exports = {
    elasticSearch: {
        mappings: {
            person: {
                properties: {
                    name: {
                        type: "string",
                    },
                    adress: {
                        type: "string",
                        index: "not_analyzed"
                    },
                    age: {
                        type: "integer",
                    },
                }
            }
        }
    }
};
Multiple adapters

To use multiple adapters for the same model. you have to make elasticsearch the last one, and manually sync create, update, destroy between adapters

module.exports = {
    connection: ['mongoConnection','elasticConnection'],
    elasticSearch: {/*...*/},
    attributes: {/*...*/},
    afterCreate: function (value, callback){
        this.createIndex(value, callback)
    },
    afterUpdate: function (value, callback){
        this.updateIndex(value.id, value, callback)
    },
    afterDestroy: function (value, callback){
        this.destroyIndex(value.id, callback)
    },
};

Warning: for sails v11.0 and earlier, connection attribute used to be defined with an 's'.

API

This adapter exposes the following methods (you can pass a callback function to them or use them as bluebird promises):

  • search(criteria, callback)

  • createIndex(value, callback) === create(value, callback)

  • updateIndex(id, value, callback) === update(id, value, callback)

  • destroyIndex(id, callback) === destroy(id, callback)

  • countIndex(criteria, callback) === count(criteria, callback)

  • bulk(body, callback)

  • client()

  • returns
    • Elasticsearch client instance to call methods directly to elasticsearch API. You can find API reference here

TODO

Fully support Semantic and Queryable interfaces.

Current Tags

  • 0.1.2                                ...           latest (2 years ago)

3 Versions

  • 0.1.2                                ...           2 years ago
  • 0.1.1                                ...           2 years ago
  • 0.1.0                                ...           3 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (5)
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |