0
0
Elasticsearchquery~10 mins

Why compound queries combine conditions in Elasticsearch - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a must condition inside the bool query.

Elasticsearch
{
  "query": {
    "bool": {
      "must": [
        [1]
      ]
    }
  }
}
Drag options to blanks, or click blank then click option'
A{"match": {"title": "Elasticsearch"}}
B{"term": {"status": "active"}}
C{"range": {"date": {"gte": "now-1d/d"}}}
D{"exists": {"field": "user"}}
Attempts:
3 left
💡 Hint
Common Mistakes
Using a condition outside an array
Using filter instead of must
2fill in blank
medium

Complete the code to add a filter condition that matches documents with status 'active'.

Elasticsearch
{
  "query": {
    "bool": {
      "filter": [
        [1]
      ]
    }
  }
}
Drag options to blanks, or click blank then click option'
A{"term": {"status": "active"}}
B{"match": {"status": "active"}}
C{"range": {"status": {"gte": "active"}}}
D{"exists": {"field": "status"}}
Attempts:
3 left
💡 Hint
Common Mistakes
Using match which is analyzed
Using range for exact match
3fill in blank
hard

Fix the error in the bool query by completing the missing must_not condition.

Elasticsearch
{
  "query": {
    "bool": {
      "must": [
        {"match": {"title": "search"}}
      ],
      "must_not": [
        [1]
      ]
    }
  }
}
Drag options to blanks, or click blank then click option'
A{"match": {"status": "active"}}
B{"exists": {"field": "user"}}
C{"range": {"date": {"lte": "now-1M/M"}}}
D{"term": {"status": "inactive"}}
Attempts:
3 left
💡 Hint
Common Mistakes
Using match instead of term
Putting conditions in wrong clauses
4fill in blank
hard

Fill both blanks to create a bool query with must and filter conditions.

Elasticsearch
{
  "query": {
    "bool": {
      "must": [
        [1]
      ],
      "filter": [
        [2]
      ]
    }
  }
}
Drag options to blanks, or click blank then click option'
A{"match": {"content": "python"}}
B{"term": {"status": "published"}}
C{"range": {"date": {"gte": "2023-01-01"}}}
D{"exists": {"field": "author"}}
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping must and filter conditions
Using match in filter
5fill in blank
hard

Fill all three blanks to build a bool query combining must, filter, and must_not conditions.

Elasticsearch
{
  "query": {
    "bool": {
      "must": [
        [1]
      ],
      "filter": [
        [2]
      ],
      "must_not": [
        [3]
      ]
    }
  }
}
Drag options to blanks, or click blank then click option'
A{"match": {"description": "database"}}
B{"term": {"status": "active"}}
C{"term": {"category": "deprecated"}}
D{"range": {"created": {"gte": "2024-01-01"}}}
Attempts:
3 left
💡 Hint
Common Mistakes
Putting must_not condition in filter
Using range instead of term for category