|Product Owner||Frances Haugenfirstname.lastname@example.org||[@frances]|
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
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.
- name: loopback-elasticsearchlocation: 'npm:@email@example.com'spec:models:- name: user- name: expense
|models||List of models to apply the search to.|
The following endpoints are provided for the search.
|POST /model/search||search||Performs a search on the model|
NYT Article Search
Search over 20 NYT articles.
The loopback-elasticsearch depends on the loopback-models module.
The following npm packages are used:
|ESHOST||Elastic search host, for example https://497d894184dd5958f9b477a5982fb1cf.ap-southeast-1.aws.found.io:9243|
|ESAUTH||Elastic search password|
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/defaultyarn install# Run tests.yarn test# Start the app.yarn start
docker pull docker.elastic.co/elasticsearch/elasticsearch:5.6.3docker 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
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.
The module contribute the elasticsearch.js helper to connect to Elasticsearh.
DEBUG=gdt:loopback:elasticsearch npm start
- Use mixins instead of generating the search method for each model