Complete the code to create a basic bool query with a must clause.
{
"query": {
"bool": {
"must": [
{ "match": { "title": "[1]" } }
]
}
}
}must with should.The must clause requires the title field to match the word "Elasticsearch".
Complete the code to add a filter clause that matches documents with status 'active'.
{
"query": {
"bool": {
"filter": [
{ "term": { "status": "[1]" } }
]
}
}
}term with match.The filter clause filters documents where the status field exactly matches "active".
Fix the error in the bool query by completing the missing clause to exclude documents with tag 'deprecated'.
{
"query": {
"bool": {
"must": [
{ "match": { "content": "search" } }
],
"[1]": [
{ "term": { "tag": "deprecated" } }
]
}
}
}filter instead of must_not to exclude documents.should which changes scoring.The must_not clause excludes documents matching the condition, here those tagged as "deprecated".
Fill both blanks to create a bool query that must match 'python' in title and should match 'tutorial' in tags.
{
"query": {
"bool": {
"[1]": [
{ "match": { "title": "python" } }
],
"[2]": [
{ "match": { "tags": "tutorial" } }
]
}
}
}must and should clauses.filter instead of should for optional matches.The must clause requires matching 'python' in the title, and the should clause boosts documents matching 'tutorial' in tags.
Fill all three blanks to create a bool query that must match 'data' in content, filters for status 'published', and excludes tag 'draft'.
{
"query": {
"bool": {
"[1]": [
{ "match": { "content": "data" } }
],
"[2]": [
{ "term": { "status": "published" } }
],
"[3]": [
{ "term": { "tag": "draft" } }
]
}
}
}filter and must_not clauses.should instead of filter for filtering.The must clause requires matching 'data' in content, filter restricts to status 'published', and must_not excludes documents tagged 'draft'.