/mongoosastic

Index Mongoose models into elasticsearch automatically.

Primary LanguageTypeScriptMIT LicenseMIT

Mongoosastic

CI workflow NPM version Coverage Status Downloads

Mongoosastic is a mongoose plugin that can automatically index your models into elasticsearch.

Getting started

  1. Install the package
npm install mongoosastic
  1. Setup your mongoose model to use the plugin
const mongoose     = require('mongoose')
const mongoosastic = require('mongoosastic')
const Schema       = mongoose.Schema

var User = new Schema({
    name: String,
    email: String,
    city: String
})

User.plugin(mongoosastic)
  1. Query your Elasticsearch with the search() method (added by the plugin)
const results = await User.search({
  query_string: {
    query: "john"
  }
});

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

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

Documentation

View docs