【问题标题】:Mongoosastic plugin doesn't update nested objectsMongoosastic 插件不会更新嵌套对象
【发布时间】: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


    【解决方案1】:

    添加参数es_schema 例如应该可以解决你的问题。

    es_schema:User.schema 
    

    【讨论】:

      猜你喜欢
      • 2018-01-15
      • 1970-01-01
      • 1970-01-01
      • 2016-02-20
      • 2021-12-15
      • 2020-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多