2

我将 elasticsearch 与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
  }

可以预见,这两种方法都不起作用。什么是正确的方法?

4

0 回答 0