0
0
Elasticsearchquery~10 mins

Bool query (must, should, must_not, filter) in Elasticsearch - Interactive Code Practice

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

Complete the code to add a must clause that matches documents where the field status is active.

Elasticsearch
{
  "query": {
    "bool": {
      "must": [
        { "term": { "status": "[1]" } }
      ]
    }
  }
}
Drag options to blanks, or click blank then click option'
Aactive
Binactive
Cpending
Ddeleted
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a status value other than 'active' will not match the requirement.
2fill in blank
medium

Complete the code to add a should clause that boosts documents with category equal to electronics.

Elasticsearch
{
  "query": {
    "bool": {
      "should": [
        { "term": { "category": "[1]" } }
      ]
    }
  }
}
Drag options to blanks, or click blank then click option'
Aelectronics
Bclothing
Cbooks
Dfurniture
Attempts:
3 left
💡 Hint
Common Mistakes
Selecting a category other than 'electronics' will not boost the right documents.
3fill in blank
hard

Fix the error in the must_not clause to exclude documents with status equal to archived.

Elasticsearch
{
  "query": {
    "bool": {
      "must_not": [
        { "term": { "status": "[1]" } }
      ]
    }
  }
}
Drag options to blanks, or click blank then click option'
Aactive
Bpending
Carchived
Ddeleted
Attempts:
3 left
💡 Hint
Common Mistakes
Using a status other than 'archived' will not exclude the correct documents.
4fill in blank
hard

Fill both blanks to create a filter clause that filters documents with price greater than 100 and less than 500.

Elasticsearch
{
  "query": {
    "bool": {
      "filter": [
        { "range": { "price": { "gt": [1], "lt": [2] } } }
      ]
    }
  }
}
Drag options to blanks, or click blank then click option'
A100
B50
C500
D1000
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the values or using incorrect numbers will filter wrong documents.
5fill in blank
hard

Fill all three blanks to build a bool query with must matching brand 'nike', should matching color 'red', and must_not matching size 'small'.

Elasticsearch
{
  "query": {
    "bool": {
      "must": [
        { "term": { "brand": "[1]" } }
      ],
      "should": [
        { "term": { "color": "[2]" } }
      ],
      "must_not": [
        { "term": { "size": "[3]" } }
      ]
    }
  }
}
Drag options to blanks, or click blank then click option'
Anike
Bred
Csmall
Dblue
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the values for each clause will cause incorrect filtering.