Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sequelastic

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sequelastic

bridge utility between sequelize-typescript and ElasticSearch

  • 0.0.9
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
24
Maintainers
2
Weekly downloads
 
Created
Source

Sequelastic

:warning: this only works with sequelize-typescript@2.x.x, in order to use this package with sequelize-typescript@1.x.x run: npm install sequelastic@0.0.7

The first sequelize-typescript and ElasticSearch bridge tool

installation

prerequisites:

in order to install sequelastic on your project just run:

npm install sequelastic

usage

first of all import and instantiate the utility:

import Sequelastic from "sequelastic";
import { model1, model2 } from "./sequelize-typescript-models";

const sequelastic = new Sequelastic({
  node: "https://elastiSearchSevice.example:9200",
  models: [model1, model2],
});

then sync your database with the elasticSearch service:

sequelastic
  .sync()
  .then((success) => {
    if (success) {
      console.log("Database synced correctly");
    } else {
      console.log("Something went wrong");
    }
  })
  .catch((err) => {
    console.error(err);
  });

now you are ready to search whatever you want with sequelastic:

sequelastic
  .search("foo", "bar", { fuzzy: true, fuzziness: "AUTO" })
  .then((results) => {
    console.log(results);
  })
  .catch((err) => {
    console.error(err);
  });

Sequelastic Functions

Constructor

create new Sequelastic instance

new Sequelastic(config: SequelasticContructorProps) => Sequelastic
propertytypedescriptiondefault
configSequelasticConstructorPropsconfig objectnone

Sync

Sync SQL database

this function will sync your database with the elasticSearch service using the following method:

  • Deleting all the pre-existing indices
  • Recreating all the indices using as index name the plural of the model name
  • using bulk insertion to add all the corresponding records
sequelastic.sync() => Promise<boolean>
propertytypedescriptiondefault
optionsSequelasticSyncOptionsconfig objectnone

Search in indices something

this function will search in elasticSearch using the search type query_string

sequelastic.search(query: string, index: string, options:SequelasticSearchOptions) => Promise<[{[key: string]: any}]> // options.wholeResponse = false

sequelastic.search(query: string, index:string, options: SequelizeSearchOptions) => Promise<elasticSearch.ApiResponse<Record<string, any>, Record<string, unknown>>> // options.wholeResponse = true
propertytypedescriptiondefault
querystringthe elasticSearch query stringnone
indexstringthe index where search for something"*"
optionsSequelasticSearchOptionssearch optionsundefined

customSearch

use a custom body for the elasticSearch _search

sequelastic.customSearch(params: elasticSearch.RequestParams.Search) => Promise<
    elasticSearch.ApiResponse<Record<string, any>, Record<string, unknown>>
  >
propertytypedescriptiondefault
paramselasicSearch.RequestParams.Searchthe custom search parameternone

searchInIndices

Make a search on different indices with a single request

this function makes a multiple search on elasticSearch adding using the same query, you can choose, for each index, the fuzziness and the pagination

sequelastic.searchInIndices(query: string, options: SequelasticMultipleSearchOptions) => Promise<
    elasticSearch.ApiResponse<Record<string, any>, Record<string, unknown>>
  >
propertytypedescriptiondefault
querystringthe search query, you can also use operatorsnone
optionsSequelasticMultipleSearchOptionsthe search optionsundefined

allIndices

Get all indices in the cluster

sequelastic.allIndices() => Promise<string[]>



Sequelastic Types

SequelasticContructorProps

keytypedescriptiondefault
nodestringelasticsearch service endpointhttp://localhost:9200
models(Model | SequelasticModelType)[]list of all the models to index[]
exclude (optional)string[]list of the model's fields to globally exclude from indexundefined

SequelasticModelType

keytypedescription
modelModelsequelize model to be indexed
attributes (optional)string[] | {exclude: string[]}fields to include or exclude in index
include (optional)(string | SequelasticModelType)[]object to eventually specify models to include in index

SequelasticSyncOptions

keytypedescriptiondefault
refreshbooleanuse refresh in elasticSearch bulk methodfalse

SequelasticSearchOptions

keytypedescriptiondefault
fuzzy (optional)booleanuse fuzzy searchfalse
fuzziness (optional)"AUTO" | numbersearch fuzziness"AUTO"
wholeResponse (optional)booleanget as return the whole search response or only the hitsfalse
from (optional)numberoffset from the first result0
size (optional)numbermaximum amount of hits to be returned10

SequelasticMultipleSearchOptions

keytypedescriptiondefault
indices (optional)(string | SequelasticMultipleSearchIndex )[]the indices where search for the queryall the indices
fuzzy (optional)booleanuse fuzzy searchfalse
fuzziness (optional)"AUTO" | numbersearch fuzziness"AUTO"
from (optional)numberoffset from the first result0
size (optional)numbermaximum amount of hits to be returned10

SequelasticMultipleSearchIndex

keytypedescriptiondefault
indexstringindex where search for the querynone
fuzzy (optional)booleanuse fuzzy searchfalse
fuzziness (optional)"AUTO" | numbersearch fuzziness"AUTO"
from (optional)numberoffset from the first result0
size (optional)numbermaximum amount of hits to be returned10

Keywords

FAQs

Package last updated on 10 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc