Giter Site home page Giter Site logo

fabien / loopback-connector-elastic-search Goto Github PK

View Code? Open in Web Editor NEW

This project forked from loopbackio/loopback-connector-elastic-search

0.0 3.0 0.0 3.72 MB

Strongloop Loopback connector for Elasticsearch

License: MIT License

JavaScript 100.00%

loopback-connector-elastic-search's Introduction

loopback-connector-elastic-search

Join the chat at https://gitter.im/strongloop-community/loopback-connector-elastic-search

Basic Elasticsearch datasource connector for Loopback.

Table of Contents generated with DocToc

Install connector from NPM

npm install loopback-connector-es --save

Configuring connector

1 . Edit datasources.json and set:

"<ConnectorEntry>": {
  "connector": "es",
  "name": "<name>",
  "index": "<index>",
  "hosts": [
        {
          "protocol": "http",
          "host": "127.0.0.1",
          "port": 9200,
          "auth": "username:password"
        }
  ],
  "apiVersion": "<apiVersion>",
  "log": "trace",
  "defaultSize": <defaultSize>,
  "requestTimeout": 30000,
  "ssl": {
      "ca": "./../cacert.pem",
      "rejectUnauthorized": true
  },
  "mappings": [
      {
          "name": "UserModel",
          "properties": {
              "realm": {"type": "string", "index" : "not_analyzed" },
              "username": {"type": "string", "index" : "not_analyzed" },
              "password": {"type": "string", "index" : "not_analyzed" },
              "email": {"type": "string", "index" : "not_analyzed" }
          }
      }
  ]
}
  1. You can peek at /examples/server/datasources.json for more hints.
  2. Services that provide ES as a hosted solution and offer an indefinite free plan for tinkering with ES:
  3. https://app.bonsai.io/plans * $0 per month * 1GB memory, 1GB storage * no CC required
  4. https://facetflow.com/#plans * $0/month * 5,000 documents, 500 MB storage * 1 primary shard, 0 replicas * Sandbox (not for production use)
  5. Free + Hosted translates to quick success in the quest to learn ES.

Required:

  • host: Elasticsearch engine host address.
  • port: Elasticsearch engine port.
  • name: Connector name.
  • connector: Elasticsearch driver.
  • index: Search engine specific index.

Optional:

  • apiVersion: specify the major version of the Elasticsearch nodes you will be connecting to.
  • log: logging option.
  • defaultSize: total number of results to return per page.
  • requestTimeout: this value is in milliseconds
  • ssl: useful for setting up a secure channel
  • protocol: can be http or https (http is the default if none specified) ... must be https if you're using ssl
  • auth: useful if you have access control setup via services like es-jetty or found or shield
  • mappings: an array of elasticsearch mappings for your various loopback models

Run example

  1. Install dependencies and start the example server
git clone https://github.com/strongloop-community/loopback-connector-elastic-search.git myEsConnector
cd myEsConnector/examples
npm install
  1. Configure the connector
  • Don't forget to create an index in your ES instance: curl -X POST https://username:[email protected]/shakespeare
  • If you mess up and want to delete, you can use: curl -X DELETE https://username:[email protected]/shakespeare
  1. Set up a cacert.pem file for communicating securely (https) with your ES instance. Download the certificate chain for your ES server using this sample (will need to be edited to use your provider) command:
cd myEsConnector
openssl s_client -connect my.es.cluster.com:9243 -showcerts | tee cacert.pem

It will be saved at the base of your cloned project. 4. Run:

cd myEsConnector/examples
DEBUG=boot:test:* node server/server.js
  • The examples/server/boot/boot.js file will automatically populate data for UserModels on your behalf when the server starts.
  1. Open this URL in your browser: http://localhost:3000/explorer
  • Try fetching all the users via the rest api console
  • You can dump all the data from your ES index, via cmd-line too: curl -X POST username:[email protected]/shakespeare/_search -d '{"query": {"match_all": {}}}'
  1. To test a specific filter via GET method, use for example: {"q" : "friends, romans, countrymen"}

Hosted ElasticSearch

Services that provide ES as a hosted solution and offer an indefinite free plan for tinkering with ES:

  1. https://app.bonsai.io/plans * $0 per month * 1GB memory, 1GB storage * no CC required
  2. https://facetflow.com/#plans * $0/month * 5,000 documents, 500 MB storage * 1 primary shard, 0 replicas * Sandbox (not for production use)
  3. Free + Hosted translates to quick success in the quest to learn ES.

Release notes

  • For this connector, you can configure an index name for your ES instance and the loopback model's name is conveniently/automatically mapped as the ES type.

  • Users must setup string fields as not_analyzed by default for predictable matches just like other loopback backends. And if more flexibility is required, multi-field mappings can be used too.

    "name" : {
        "type" : "multi_field",
        "fields" : {
            "name" : {"type" : "string", "index" : "not_analyzed"},
            "native" : {"type" : "string", "index" : "analyzed"}
        }
    }
    ...
    // this will treat 'George Harrison' as 'George Harrison' in a search
    User.find({order: 'name'}, function (err, users) {..}
    // this will treat 'George Harrison' as two tokens: 'george' and 'harrison' in a search
    User.find({order: 'name', where: {'name.native': 'Harrison'}}, function (err, users) {..}
    
  • TBD

loopback-connector-elastic-search's People

Contributors

pulkitsinghal avatar drakerian avatar lrossy avatar yagobski avatar gitter-badger avatar

Watchers

Fabien Franzen avatar James Cloos avatar  avatar

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.