6

我试图根据几个因素向用户提出建议:

•建议只能是来自同一所大学的学生 •建议必须至少匹配一个其他领域

我以为我有它,但问题是这个查询将返回来自同一所学校的所有学生,而不管其他一切:

PUT /user/.percolator/4
{
  "query": {
    "bool": {
    "must": [
        { "match": { "college":{
            "query" : "Oakland University",
            "type" : "phrase"
        }}}
    ],
      "should": [

            { "match": { "hashtag": "#chipotle" }},
            { "match": { "hashtag": "#running"}},
            { "match": { "college_course": "ART-160" }}

      ]
    }
  }
}

POST /user/stuff/_percolate/
{  
  "doc":{  

    "college":"Oakland University",
    "college_course": "WRT BIO MTH-400"


  }
}
4

1 回答 1

9

这是因为 should 和 must 的行为在同一个 bool 查询中。默认情况下,不需要匹配任何“should”子句,除非您的 bool 仅包含“should”子句,否则它至少需要匹配一个。

为了解决你的问题,你只需要"minimum_should_match" : 1在你的布尔查询中添加:)

于 2015-09-10T14:42:42.587 回答