所以这个项目包括下一个堆栈,NodeJS,Express,Mongodb,ElasticSearch。为了索引到弹性搜索,我们使用插件mongoosastic。
我有以下模型,它们之间具有1:M的关系,每当我更新组时,我希望组也在user对象中更新。因此,如果我更新组,它只是在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');提前感谢!
发布于 2019-04-04 08:33:02
添加参数es_schema,例如应该解决您的问题。
es_schema:User.schema https://stackoverflow.com/questions/52717000
复制相似问题