首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mongoosastic插件不更新嵌套对象

Mongoosastic插件不更新嵌套对象
EN

Stack Overflow用户
提问于 2018-10-09 16:53:45
回答 1查看 388关注 0票数 1

所以这个项目包括下一个堆栈,NodeJS,Express,Mongodb,ElasticSearch。为了索引到弹性搜索,我们使用插件mongoosastic。

我有以下模型,它们之间具有1:M的关系,每当我更新组时,我希望组也在user对象中更新。因此,如果我更新组,它只是在ElasticSearch的组索引中更新,而不是在用户索引中也更新。但是如果我再次更新用户,组对象就被正确实现了。这应该与es_type和es_include_in_parent有关,但这两种方式都不起作用。

代码语言:javascript
复制
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');

代码语言:javascript
复制
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');

提前感谢!

EN

回答 1

Stack Overflow用户

发布于 2019-04-04 08:33:02

添加参数es_schema,例如应该解决您的问题。

代码语言:javascript
复制
es_schema:User.schema 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52717000

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档