Search code examples
mongodbelasticsearchmongoosemongoosastic

Store data in ES and not on MongoDB using mongoosastic


I am trying to build a search engine project using mongoosastic and was wondering if there was a way to store specific data fields only on elasticsearch and not on MongoDB as this would basically make it duplication of data.

For example we can use the es_indexed to make sure elasticsearch indexes the data and stores it to MongoDB but is there something similar which can make sure elasticsearch indexes the data but MongoDb does not store it.

var mongoose     = require('mongoose')
  , mongoosastic = require('mongoosastic')
  , Schema       = mongoose.Schema

var User = new Schema({
    name: {type:String, es_indexed:true}
  , email: String
  , city: String
  , comments: {type:[Comment], es_indexed:true}
})

User.plugin(mongoosastic)

I was checking the same with mongoose as well but it wasn't working. How can i achieve this?


Solution

  • Using select: false will insert the data only to elasticsearch and not mongodb

    var mongoose     = require('mongoose')
      , mongoosastic = require('mongoosastic')
      , Schema       = mongoose.Schema
    
    var User = new Schema({
        name: {type:String, es_indexed:true}
      , email: String
      , city: String
      , comments: {type:[Comment], es_indexed:true, select: false}
    })
    
    User.plugin(mongoosastic)