Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

mongoosastic-ts

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoosastic-ts

A mongoose plugin that indexes models into elastic search

latest
Source
npmnpm
Version
6.0.3
Version published
Maintainers
1
Created
Source

mongoosastic-ts

Build Status 7 Build Status 8.0 Build Status 8.2 Build Status 8.5 Build Status 8.6 NPM version Downloads UNPKG

mongoosastic-ts is a mongoose plugin that can automatically index your models into elasticsearch.

This package is forked version from mongoosastic

It has been updated and migrated to typescript and updated dependencies and codebase to the latest packages

Support elasticsearch 7.x and 8.x

Getting started

  • Install the package
npm install -S mongoosastic-ts
  • Setup your mongoose model to use the plugin
import { mongoosastic } from 'mongoosastic-ts';
import { MongoosasticDocument, MongoosasticModel, MongoosasticPluginOpts } from 'mongoosastic-ts/dist/types';
import { Document, Schema, model } from 'mongoose';

export interface IBookModel extends Document, MongoosasticDocument {
  title?: string;
}

const BookSchema = new Schema<IBookModel>({
  title: {
    type: String,
    required: true,
  },
});

BookSchema.plugin(mongoosastic, {
  index: 'books',
  type: 'book',
} as MongoosasticPluginOpts);

export const bookModel = model<IBookModel, MongoosasticModel<IBookModel>>('Book', BookSchema);
  • Query your Elasticsearch with the search() method (added by the plugin)
const results = await bookModel.search({
  query_string: {
    query: "john"
});
// do something with elastic search results

NOTE: You can also query Elasticsearch with any other method. Example:

curl http://localhost:9200/users/user/_search

Documentation

View docs

Keywords

mongoose-sync-elasticsearch

FAQs

Package last updated on 23 Feb 2023

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