【问题标题】:Elastic Search MUST + at least one SHOULD in percolator queryElastic Search 必须 + 至少一个应该在 percolator 查询中
【发布时间】:2015-09-10 22:42:42
【问题描述】:

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

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

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

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"


  }
}

【问题讨论】:

    标签: elasticsearch elasticsearch-percolate


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-07
      • 1970-01-01
      相关资源
      最近更新 更多