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

sequelastic

v0.0.9

Published

bridge utility between sequelize-typescript and ElasticSearch

Downloads

45

Readme

Sequelastic

:warning: this only works with [email protected], in order to use this package with [email protected] run: npm install [email protected]

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

| property | type | description | default | | :------: | :--------------------------------------------------------: | :-----------: | :-----: | | config | SequelasticConstructorProps | config object | none |

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>

| property | type | description | default | | :------: | :---------------------------------------------------: | :-----------: | :-----: | | options | SequelasticSyncOptions | config object | none |

Search

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

| property | type | description | default | | :------: | :----------------------------------------------------------------------------------------------------------------: | :----------------------------------: | :-------: | | query | string | the elasticSearch query string | none | | index | string | the index where search for something | "*" | | options | SequelasticSearchOptions | search options | undefined |

customSearch

use a custom body for the elasticSearch _search

sequelastic.customSearch(params: elasticSearch.RequestParams.Search) => Promise<
    elasticSearch.ApiResponse<Record<string, any>, Record<string, unknown>>
  >

| property | type | description | default | | :------: | :-----------------------------------------------------------------------------------------------------------------------------------------: | :-------------------------: | :-----: | | params | elasicSearch.RequestParams.Search | the custom search parameter | none |

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>>
  >

| property | type | description | default | | :------: | :----------------------------------------------------------------------------------------------------------------: | :------------------------------------------: | :-------: | | query | string | the search query, you can also use operators | none | | options | SequelasticMultipleSearchOptions | the search options | undefined |

allIndices

Get all indices in the cluster

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

Sequelastic Types

SequelasticContructorProps

| key | type | description | default | | :------------------: | :----------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------: | :-------------------: | | node | string | elasticsearch service endpoint | http://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 index | undefined |

SequelasticModelType

| key | type | description | | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------- | | model | Model | sequelize 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

| key | type | description | default | | :-----: | :------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------: | :-----: | | refresh | boolean | use refresh in elasticSearch bulk method | false |

SequelasticSearchOptions

| key | type | description | default | | :------------------------: | :--------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------: | :-----: | | fuzzy (optional) | boolean | use fuzzy search | false | | fuzziness (optional) | "AUTO" | number | search fuzziness | "AUTO" | | wholeResponse (optional) | boolean | get as return the whole search response or only the hits | false | | from (optional) | number | offset from the first result | 0 | | size (optional) | number | maximum amount of hits to be returned | 10 |

SequelasticMultipleSearchOptions

| key | type | description | default | | :--------------------: | :--------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------: | :-------------: | | indices (optional) | (string | SequelasticMultipleSearchIndex )[] | the indices where search for the query | all the indices | | fuzzy (optional) | boolean | use fuzzy search | false | | fuzziness (optional) | "AUTO" | number | search fuzziness | "AUTO" | | from (optional) | number | offset from the first result | 0 | | size (optional) | number | maximum amount of hits to be returned | 10 |

SequelasticMultipleSearchIndex

| key | type | description | default | | :--------------------: | :--------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------: | :-----: | | index | string | index where search for the query | none | | fuzzy (optional) | boolean | use fuzzy search | false | | fuzziness (optional) | "AUTO" | number | search fuzziness | "AUTO" | | from (optional) | number | offset from the first result | 0 | | size (optional) | number | maximum amount of hits to be returned | 10 |