elasticsearch operator minimum_should_match如何使用
时间: 2023-08-14 21:05:30 浏览: 61
`minimum_should_match`参数可以在Elasticsearch Operator的布尔查询中使用。以下是一些使用`minimum_should_match`的示例:
1. 作为整个布尔查询的参数:
```
GET /_search
{
"query": {
"bool": {
"should": [
{ "match": { "title": "apple" }},
{ "match": { "title": "banana" }},
{ "match": { "title": "cherry" }}
],
"minimum_should_match": 2
}
}
}
```
在上面的例子中,如果至少有两个should子句匹配,整个布尔查询才会被认为是匹配的。
2. 作为should子句的参数:
```
GET /_search
{
"query": {
"bool": {
"should": [
{ "match": { "title": { "query": "apple", "minimum_should_match": 2 } }},
{ "match": { "title": "banana" }},
{ "match": { "title": "cherry" }}
]
}
}
}
```
在上面的例子中,如果第一个should子句中至少有两个term匹配,整个should子句才会被认为是匹配的。
3. 作为百分比的参数:
```
GET /_search
{
"query": {
"bool": {
"should": [
{ "match": { "title": "apple" }},
{ "match": { "title": "banana" }},
{ "match": { "title": "cherry" }}
],
"minimum_should_match": "50%"
}
}
}
```
在上面的例子中,如果至少有50%的should子句匹配,整个布尔查询才会被认为是匹配的。
请注意,`minimum_should_match`是可选参数,如果未指定,则默认情况下将所有should子句都视为必须匹配。