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

@gigster/module-loopback-elasticsearch

v2.0.0

Published

Role | Name | Email | Slack ---- | ---- | ----- | ----- *Product Owner* | Frances Haugen | [[email protected]](mailto:[email protected]) | [@frances] *Maintainer* | Alice Wang | [[email protected]](mailto:[email protected]) | [@alicebot] *Developer* |

Downloads

62

Readme

loopback-elasticsearch

Role | Name | Email | Slack ---- | ---- | ----- | ----- Product Owner | Frances Haugen | [email protected] | [@frances] Maintainer | Alice Wang | [email protected] | [@alicebot] Developer | Jerome Curlier | [email protected] | [@jerome]

Why Use ElasticSearch?

Traditional relational databases excel at precise and exact matches. While ElasticSearch can perform exact matching and statistical calculations, its strength lies in an approximation task based on scores of its search results.

Taken from the following Stackexchange answer:

The following examples highlight some good use cases for ElasticSearch:

  • Searching a large number of product descriptions for the best match for a specific phrase (ie "chef’s knife") and returning the most relevant results
  • Given the previous example, breaking down the various departments where "chef’s knife" appears
  • Searching text for words that sound like "season"
  • Auto-completing a search box based on partially typed words based on previously issued searches, accounting for misspellings
  • Storing a large quantity of semi-structured (JSON) data in a distributed fashion, with a specified level of redundancy across a cluster of machines (multitenancy)

Not so good candidates for ElasticSearch:

  • Calculating how many items are left in the inventory
  • Figuring out the sum of all line-items on all the invoices sent out in a given month
  • Executing two operations transactionally with rollback support
  • Creating records that are guaranteed to be unique across multiple given terms, for instance a phone number and extension

Overview

This module provides elastic search for Loopback.

The module is based on the blog post Integrating LoopBack with ElasticSearch. Please therefore review the post to learn about this module.

It consumes the ElasticSearch API through the JavaScript client: ElasticSearch API

Usage

- name: loopback-elasticsearch
        location: 'npm:@gigster/[email protected]'
  spec:
    models:
      - name: user
      - name: expense

Specification

Name | Status ---- | ----- models | List of models to apply the search to.

Endpoints

The following endpoints are provided for the search.

Endpoint | Method | Description ---- | ---- | ----- POST /model/search | search | Performs a search on the model

Examples

NYT Article Search

Search over 20 NYT articles.

Dependencies

The loopback-elasticsearch depends on the loopback-models module.

The following npm packages are used:

npm | version ---- | ----- elasticsearch | ^13.3.1

Environment variables

Name | Description ---- | ----- ESHOST | Elastic search host, for example https://497d894184dd5958f9b477a5982fb1cf.ap-southeast-1.aws.found.io:9243 ESAUTH | Elastic search password

Tests

Module tests are defined using a test/scenarios.yaml file. This file defines the set of example gigs that we generate as part of integration testing. To run all tests, run yarn test at the root of this module.

Each scenario is generated in test/scenario/<name> which you can then cd into and run the actual app. For a scenario called default, this is done via:

cd test/scenario/default
yarn install

# Run tests.
yarn test

# Start the app.
yarn start

Docker

docker pull docker.elastic.co/elasticsearch/elasticsearch:5.6.3
docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:5.6.3

Then start the applccation with the default password.

ESAUTH=elastic:changeme npm start

Generation

Models

For each model, the module contributes a search endpoint. The implementation of the search is provided as a method on the model in a file search.js in the model folder.

Helper

The module contribute the elasticsearch.js helper to connect to Elasticsearh.

Troubleshooting

DEBUG=gdt:loopback:elasticsearch npm start

TODO

  • Use mixins instead of generating the search method for each model