我用这两个查询进行测试
用must查询
{
"size": 200,
"from": 0,
"query": {
"bool": {
"must": [ {
"match": {
"_all": "science"
}
},
{
"match": {
"category": "fiction"
}
},
{
"match": {
"country": "us"
}
}
]
}
}
用 should + minimum_should_match 查询
{
"size": 200,
"from": 0,
"query": {
"bool": {
"should": [ {
"match": {
"_all": "science"
}
},
{
"match": {
"category": "fiction"
}
},
{
"match": {
"country": "us"
}
}
],
minimum_should_match: 3
}
}
}
两个查询都给我相同的结果,我不知道这两个之间的区别,什么时候我们应该使用 minimum_should_match?
我猜你的意思是minimum_number_should_match
,对吧?
在这两种情况下,它都是一样的,因为 should
中的子句数量相同。 minimum_number_should_match
通常在您的子句多于您在此处指定的数量时使用。
例如,如果您有 5 个 should 子句,但出于某种原因您只需要满足其中的三个子句,您可以这样做:
{
"query": {
"bool": {
"should": [
{
"term": {
"tag": "wow"
}
},
{
"term": {
"tag": "elasticsearch"
}
},
{
"term": {
"tag": "tech"
}
},
{
"term": {
"user": "plchia"
}
},
{
"range": {
"age": {
"gte": 10,
"lte": 20
}
}
}
],
"minimum_should_match": 3
}
}
}
Tôi là một lập trình viên xuất sắc, rất giỏi!