2.0.0 • Published 6 years ago

@gigster/module-loopback-elasticsearch v2.0.0

Weekly downloads
37
License
UNLICENSED
Repository
-
Last release
6 years ago

loopback-elasticsearch

RoleNameEmailSlack
Product OwnerFrances Haugenfrances@gigster.com@frances
MaintainerAlice Wangalice@gigster.com@alicebot
DeveloperJerome Curlierjerome@gigster.com@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/loopback-elasticsearch@1.1.0'
  spec:
    models:
      - name: user
      - name: expense

Specification

NameStatus
modelsList of models to apply the search to.

Endpoints

The following endpoints are provided for the search.

EndpointMethodDescription
POST /model/searchsearchPerforms 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:

npmversion
elasticsearch^13.3.1

Environment variables

NameDescription
ESHOSTElastic search host, for example https://497d894184dd5958f9b477a5982fb1cf.ap-southeast-1.aws.found.io:9243
ESAUTHElastic 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
2.0.0

6 years ago

1.2.11

6 years ago

1.2.10

6 years ago

1.2.9

6 years ago

1.2.8

6 years ago

1.2.7

6 years ago

1.2.6

6 years ago

1.2.5

6 years ago

1.2.4

6 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.1.0-alpha.2

6 years ago

1.1.0-alpha.1

6 years ago

1.0.0

6 years ago