gpt4 book ai didi

Elasticsearch:应该 + minimum_should_match 与必须

转载 作者:行者123 更新时间:2023-11-29 02:51:13 36 4
gpt4 key购买 nike

我用这两个查询进行测试

用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
}
}
}

关于Elasticsearch:应该 + minimum_should_match 与必须,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42830882/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com