Giter Site home page Giter Site logo

sails-elasticsearch's Introduction

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: '2.0'
},

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.

sails-elasticsearch's People

Contributors

gitter-badger avatar marsanla avatar mie00 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

sails-elasticsearch's Issues

Does not support promises

It'd be nice if .search and the other methods supported them since bluebird is already a dependency.

Thank you for sharing this module!

Multiple connections don't work (sails 0.12.1)

After a long search, this is I think the best implementation of elastic search for sailsjs.
I'm trying to make it work with MongoDB, so I use the multiple connections in a model specified on the documentation.

models/Plant.js
... connections: ['envMongodbServer','envElasticsearchServer'], ...

I get this error when trying to do this:
Plant.search(query)

TypeError: Plant.search is not a function

Any thoughts on why I'm getting this? Thank you so much for your great work and support!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.