我正在尝试使用mongoosastic构建一个搜索引擎项目,并且想知道是否有一种方法可以仅在elasticsearch而不是MongoDB上存储特定的数据字段,因为这基本上会使数据重复。

例如,我们可以使用es_indexed来确保elasticsearch对数据进行索引并将其存储到MongoDB中,但是是否有类似的东西可以确保elasticsearch对数据进行索引但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}
})

User.plugin(mongoosastic)

我也在mongoose上进行了检查,但是没有用。
我怎样才能做到这一点?

最佳答案

使用select: false只会将数据插入elasticsearch而不是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)

关于mongodb - 使用mongoosastic将数据存储在ES中而不是MongoDB中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53235643/

10-16 09:46