我正在尝试使用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/