A mongoose plugin that indexes models into elastic search
npm install mongoosasticMongoosastic is a mongoose plugin that can automatically index your models into elasticsearch.
1. Install the package
``bash`
npm install mongoosastic
2. Setup your mongoose model to use the plugin
`javascript
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)
`
3. Query your Elasticsearch with the search() method (added by the plugin)
`javascript`
const results = await User.search({
query_string: {
query: "john"
}
});
NOTE: You can also query Elasticsearch with any other method. Example:
`bash``
curl http://localhost:9200/users/user/_search