npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@atelierfabien/loopback-connector-es

v0.3.2

Published

Connect LoopBack to Elasticsearch engine

Downloads

2

Readme

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