0
0
Elasticsearchquery~10 mins

Filter aggregation 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 filter aggregation that matches documents where the field "status" is "active".

Elasticsearch
{
  "aggs": {
    "active_users": {
      "filter": {
        "term": { "status": [1] }
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
A"deleted"
B"inactive"
C"pending"
D"active"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong status value like "inactive" or "pending".
Forgetting to put quotes around the string value.
2fill in blank
medium

Complete the code to add a filter aggregation that matches documents where the "age" field is greater than 30.

Elasticsearch
{
  "aggs": {
    "age_filter": {
      "filter": {
        "range": { "age": { "[1]": 30 } }
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Alt
Bgt
Cgte
Dlte
Attempts:
3 left
💡 Hint
Common Mistakes
Using "lt" or "lte" which filter for less than values.
Confusing "gte" with "gt".
3fill in blank
hard

Fix the error in the filter aggregation to correctly filter documents where "category" is "books".

Elasticsearch
{
  "aggs": {
    "books_filter": {
      "filter": {
        "term": { "category": [1] }
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
A"books"
Bbooks
C'books'
Dcategory
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted strings which cause JSON errors.
Using single quotes which are invalid in JSON.
4fill in blank
hard

Fill both blanks to create a filter aggregation that matches documents where "price" is between 10 and 50 inclusive.

Elasticsearch
{
  "aggs": {
    "price_range": {
      "filter": {
        "range": { "price": { [1]: 10, [2]: 50 } }
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
A"gte"
B"lt"
C"lte"
D"gt"
Attempts:
3 left
💡 Hint
Common Mistakes
Using "gt" or "lt" which exclude boundary values.
Mixing up the operators or using invalid keys.
5fill in blank
hard

Fill all three blanks to create a filter aggregation that matches documents where "tags" contain "python" and the "rating" is greater than 4.

Elasticsearch
{
  "aggs": {
    "python_high_rating": {
      "filter": {
        "bool": {
          "must": [
            { "term": { "tags": [1] } },
            { "range": { "rating": { [2]: [3] } } }
          ]
        }
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
A"python"
B"gt"
C4
D"gte"
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted strings for term values.
Using "gte" instead of "gt" if strictly greater is required.
Putting the number 4 in quotes which makes it a string.