【发布时间】:2019-03-13 23:51:48
【问题描述】:
所以该项目由下一个堆栈、NodeJS、Express、Mongodb、ElasticSearch 组成。对于弹性搜索的索引,我们使用插件 mongoosastic。
我有以下模型,它们之间具有 1:M 关系,每当我更新组时,我也希望在用户对象中更新组。 因此,如果我更新组,它只会在 ElasticSearch 的组索引中更新,而不是在用户索引中。但是,如果我再次更新用户,组对象就会正确实现。 它应该是 es_type 和 es_include_in_parent 的东西,但是这两种方式都不起作用。
const UserSchema: mongoose.Schema = new mongoose.Schema({
email: String,
password: String,
group: {
type: mongoose.Schema.Types.ObjectId,
ref: 'groups',
es_indexed: true,
es_type: 'nested',
es_include_in_parent: true
}
}, { timestamps: true } as SchemaOptions);
UserSchema.plugin(mongoosastic, {..elasticSearchConfig,
index: 'users',
populate: [
{path: 'group', model: 'groups'}
]}
);
export const UserModel = mongoose.model('users', UserSchema, 'users');
和
export const GroupSchema: mongoose.Schema = extendBaseSchema(new mongoose.Schema({
name: { type: String, es_indexed: true },
web: { type: String, es_indexed: true },
users: [
{
type: mongoose.Schema.Types.ObjectId,
ref: 'users',
es_indexed: true,
es_type: 'nested',
es_include_in_parent: true
}
],
}));
GroupSchema.plugin(mongoosastic, {...elasticSearchConfig,
index: 'groups'
});
export const GroupModel = mongoose.model('groups', GroupSchema, 'groups');
提前致谢!
【问题讨论】:
标签: node.js mongodb elasticsearch mongoose mongoosastic