6

Im trying to make suggestions to users based on several factors:

•Suggestions MUST only be students from the same college •Suggestions MUST match at least one other field

I thought I had it but the problem is this query will return ALL students from the same school regardless of everything else:

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"


  }
}
ChuckKelly
  • 1,742
  • 5
  • 25
  • 54

1 Answers1

12

This is because the behavior of should and must in the same bool query. By default none of the "should" clauses are required to match, unless your bool contains only the "should" clause then it's required to match at least one.

To solve you problem, you just need to add "minimum_should_match" : 1 inside your bool query :)

Ryan Huynh.
  • 306
  • 2
  • 9