我已经工作了,但是它与npm / github上给出的示例有很大不同。
我必须删除es_schema:样式(就像我偶然为品牌所做的那样,这就是它起作用的原因)。我必须添加es_type:“ nested” /
es_include_in_parent,该文件是我从elasticsearch和mongoosastic文档中收集的。
我不确定这是故意的,但它似乎可以工作:
style: {type: mongoose.Schema.Types.ObjectId, ref: 'Style', es_type:'nested', es_include_in_parent:true},现在,当我console.log results.hits时,得到:style:[Object]根据需要。
以下是npm中给出的示例,它对我不起作用:
var Comment = new Schema({ title: String , body: String , author: String});var User = new Schema({ name: {type:String, es_indexed:true} , email: String , city: String , comments: {type: Schema.Types.ObjectId, ref: 'Comment', es_schema: Comment, es_indexed:true, es_select: 'title body'}})User.plugin(mongoosastic, { populate: [ {path: 'comments', select: 'title body'} ]})


