Given the following Elasticsearch bool query, what documents will match?
{
"query": {
"bool": {
"must": [
{ "term": { "status": "active" } }
],
"should": [
{ "term": { "role": "admin" } },
{ "term": { "role": "user" } }
],
"minimum_should_match": 1
}
}
}Assuming documents have fields status and role, which option best describes the matching documents?
{
"query": {
"bool": {
"must": [
{ "term": { "status": "active" } }
],
"should": [
{ "term": { "role": "admin" } },
{ "term": { "role": "user" } }
],
"minimum_should_match": 1
}
}
}Remember that must means all conditions must be true, and should means at least one should match if minimum_should_match is set.
The must clause requires documents to have status equal to 'active'. The should clause requires at least one of the roles 'admin' or 'user' to match because minimum_should_match is 1. So documents must have status 'active' and role either 'admin' or 'user'.
What documents will match this Elasticsearch bool query?
{
"query": {
"bool": {
"must": [
{ "term": { "category": "books" } }
],
"must_not": [
{ "term": { "author": "unknown" } }
]
}
}
}{
"query": {
"bool": {
"must": [
{ "term": { "category": "books" } }
],
"must_not": [
{ "term": { "author": "unknown" } }
]
}
}
}The must_not clause excludes documents matching its conditions.
The must clause requires documents to be in category 'books'. The must_not clause excludes documents where author is 'unknown'. So the result is documents in 'books' category but not authored by 'unknown'.
What error will this Elasticsearch query produce?
{
"query": {
"bool": {
"filter": {
"term": { "status": "active" }
},
"must": [
{ "term": { "role": "admin" } }
]
}
}
}{
"query": {
"bool": {
"filter": {
"term": { "status": "active" }
},
"must": [
{ "term": { "role": "admin" } }
]
}
}
}Check the Elasticsearch documentation for filter clause format.
The filter clause can be an object or an array of queries. Here it is a single term query, which is valid. It works together with must to filter documents with status 'active' and role 'admin'. No error occurs.
Which of the following Bool queries is syntactically correct in Elasticsearch?
The must clause expects an array of queries.
Option A correctly uses an array for must with a valid term query object inside. Option A uses an object instead of an array. Option A uses terms without a field key properly structured (missing field key). Option A uses terms with a single string instead of an array.
You want to find documents that meet all these conditions:
- Have
statusequal to 'published'. - Either
categoryis 'technology' ortagscontain 'innovation'. - Must not have
authorequal to 'anonymous'. - Filter to only include documents with
viewsgreater than 1000.
Which Bool query JSON correctly implements these conditions?
Use should with minimum_should_match for OR conditions inside must.
Option A correctly uses a nested bool with should and minimum_should_match inside the must array to express the OR condition between category and tags. It also uses must_not to exclude author 'anonymous' and a filter with a range query for views > 1000. Other options either require both category and tags (B and D) or put should at the top level without nesting inside must (C), which changes the logic.