我试图根据几个因素向用户提出建议:
•建议只能是同一所大学的学生•建议必须至少匹配一个其他字段
我以为我有它,但问题是这个查询将返回同一所学校的所有学生,而不管其他情况:
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"
}
}
这是因为 should 和 must 的行为在同一个 bool 查询中。默认情况下,不需要匹配任何“should”子句,除非您的 bool 仅包含“should”子句,否则它至少需要匹配一个子句。
要解决您的问题,您只需在 bool 查询中添加 "minimum_should_match": 1
:)
Tôi là một lập trình viên xuất sắc, rất giỏi!