Elastic search with Mongoose - integrated schema

I have the following mongoose pattern:

var ReviewSchema = new Schema({ title: String, details: String, user: {type: ObjectId, ref:'User'}, }); var SubjectSchema = new Schema({ name: {type: String, required: true}, website: {type: String, index: { unique: true }}, review: {type: [ReviewSchema], es_indexed:true} }); 

I have another User schema referenced by Review .

I tried the mongoosastic plugin, but I can not find ways to index the link scheme. I want to index the username of the review. Therefore, I just used an elastic search client for this.

Each search / update / delete review I searched in the database and updated the elastic search index with the value obtained from the database. Is there a better way to do this when updating the index when updating the inline schema? Thanks

+4
source share
1 answer

This can be done using mongoosastic . There is an option to populate, for example, in Mongoose in mongoosastic , with which you can index mongoose links.

 ReviewSchema.plugin(mongoosastic, { populate: [ {path: 'User', select: 'name'} ] }) 

Further information on this can be found in the documentation here .

+1
source

Source: https://habr.com/ru/post/1501966/


All Articles