0
0
Elasticsearchquery~10 mins

Bool query in depth 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 create a basic bool query with a must clause.

Elasticsearch
{
  "query": {
    "bool": {
      "must": [
        { "match": { "title": "[1]" } }
      ]
    }
  }
}
Drag options to blanks, or click blank then click option'
Aindex
Bdatabase
Cquery
DElasticsearch
Attempts:
3 left
💡 Hint
Common Mistakes
Using a word not related to the field.
Confusing must with should.
2fill in blank
medium

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

Elasticsearch
{
  "query": {
    "bool": {
      "filter": [
        { "term": { "status": "[1]" } }
      ]
    }
  }
}
Drag options to blanks, or click blank then click option'
Aactive
Bpending
Cclosed
Ddeleted
Attempts:
3 left
💡 Hint
Common Mistakes
Using a status that does not exist in the data.
Confusing term with match.
3fill in blank
hard

Fix the error in the bool query by completing the missing clause to exclude documents with tag 'deprecated'.

Elasticsearch
{
  "query": {
    "bool": {
      "must": [
        { "match": { "content": "search" } }
      ],
      "[1]": [
        { "term": { "tag": "deprecated" } }
      ]
    }
  }
}
Drag options to blanks, or click blank then click option'
Amust_not
Bmust
Cshould
Dfilter
Attempts:
3 left
💡 Hint
Common Mistakes
Using filter instead of must_not to exclude documents.
Adding the clause under should which changes scoring.
4fill in blank
hard

Fill both blanks to create a bool query that must match 'python' in title and should match 'tutorial' in tags.

Elasticsearch
{
  "query": {
    "bool": {
      "[1]": [
        { "match": { "title": "python" } }
      ],
      "[2]": [
        { "match": { "tags": "tutorial" } }
      ]
    }
  }
}
Drag options to blanks, or click blank then click option'
Amust
Bfilter
Cshould
Dmust_not
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping must and should clauses.
Using filter instead of should for optional matches.
5fill in blank
hard

Fill all three blanks to create a bool query that must match 'data' in content, filters for status 'published', and excludes tag 'draft'.

Elasticsearch
{
  "query": {
    "bool": {
      "[1]": [
        { "match": { "content": "data" } }
      ],
      "[2]": [
        { "term": { "status": "published" } }
      ],
      "[3]": [
        { "term": { "tag": "draft" } }
      ]
    }
  }
}
Drag options to blanks, or click blank then click option'
Amust
Bfilter
Cmust_not
Dshould
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up filter and must_not clauses.
Using should instead of filter for filtering.