我将弹性搜索与Mongoosastic插件结合使用。我查询用户,我只想检索属于具有特定对象ID的特定组的用户。如何添加对象ID进行搜索?基本搜索(无ID)如下所示:
User.search({
query_string: {
query: req.body.query + '*' // '*' used for wildcard matching
}
}, {hydrate: true}, (err, results) => {
...
这是我的架构
const UserSchema = new Schema({
firstName: {
type: String,
trim: true,
lowercase: true,
es_indexed:true
},
lastName: {
type: String,
trim: true,
lowercase: true,
es_indexed:true
},
email: {
type: String,
lowercase: true,
trim: true,
es_indexed:true
},
password: {type: String},
_team: {type: Schema.Types.ObjectId, ref: 'Team'}, //Object Id I'm trying to filter
});
我试过传递
User.find()
搜索之前,将_team添加到查询字符串
query_string: {
query: req.body.query + '*',
_team: req.team
}
这两种方法都可以预测不起作用。什么是正确的方法呢?