1, the concept of
BOOL (Boolean) filter. This is a complex filter (compound filter), it can accept a plurality of additional filters as parameters, and combined into a variety of Boolean (logical) a combination of these filters.
Format
a bool filter consists of three parts:
{
"bool" : {
"must" : [],
"should" : [],
"must_not" : [],
}
}
must
all statements must (must) match, and AND equivalence.
must_not
all the statements can not (must not) match, and NOT equivalent.
You should
have to match at least one statement, the OR equivalent.
2, combat
Query title: chrome or firefox data is: Should there be at least one default match the following example:
{
"bool": {
"should": [
{ "term": { "title": "chrome" }},
{ "term": { "title": "firefox" }}
]
}
}
Query title: a chrome or firefox or safari of data: Because only three statements, the query term parameter minimum_should_match
value will be truncated to 75 percent 2
. I.e., three should
statements must match at least the following two cases:
{
"bool": {
"should": [
{ "term": { "title": "chrome" }},
{ "term": { "title": "firefox" }},
{ "term": { "title": "safari" }}
],
"minimum_should_match": 2
}
}
Query title: there must be both chrome firefox, strong query in the following example:
{
"bool": {
"must": [
{ "term": { "title": "chrome" }},
{ "term": { "title": "firefox" }}
]
}
}
Query title: chrome must not contain strong query following example:
{
"bool": {
"must_not": [
{ "term": { "title": "chrome"}}
]
}
}
Reference section from:
Elasticsearch: Boolean (bool) filter --AND, OR, NOT query, query a plurality of fields