0
0
Elasticsearchquery~10 mins

Range buckets 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 define a range bucket aggregation named "price_ranges".

Elasticsearch
{
  "aggs": {
    "price_ranges": {
      "range": {
        "field": "price",
        "ranges": [
          { "to": 100 },
          { "from": 100, "to": 200 },
          { "from": 200 }
        ]
      }
    }
  },
  "size": [1]
}
Drag options to blanks, or click blank then click option'
A0
B10
C100
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Setting "size" to a positive number returns documents, not just aggregation results.
Omitting "size" returns default 10 documents, which is unnecessary here.
2fill in blank
medium

Complete the code to add a sub-aggregation "avg_price" that calculates the average price within each range bucket.

Elasticsearch
{
  "aggs": {
    "price_ranges": {
      "range": {
        "field": "price",
        "ranges": [
          { "to": 100 },
          { "from": 100, "to": 200 },
          { "from": 200 }
        ]
      },
      "aggs": {
        "avg_price": {
          "[1]": {
            "field": "price"
          }
        }
      }
    }
  },
  "size": 0
}
Drag options to blanks, or click blank then click option'
Asum
Bavg
Cmax
Dmin
Attempts:
3 left
💡 Hint
Common Mistakes
Using "sum" instead of "avg" returns total sum, not average.
Using "max" or "min" returns maximum or minimum values, not average.
3fill in blank
hard

Fix the error in the range bucket definition by completing the missing key.

Elasticsearch
{
  "aggs": {
    "age_ranges": {
      "range": {
        "[1]": "age",
        "ranges": [
          { "to": 20 },
          { "from": 20, "to": 40 },
          { "from": 40 }
        ]
      }
    }
  },
  "size": 0
}
Drag options to blanks, or click blank then click option'
Avalue
Branges
Cfield
Dkey
Attempts:
3 left
💡 Hint
Common Mistakes
Using "ranges" as a key for the field causes an error.
Using "key" or "value" are not valid keys for this purpose.
4fill in blank
hard

Fill both blanks to create a range bucket aggregation on "weight" with two buckets: less than 50 and 50 or more.

Elasticsearch
{
  "aggs": {
    "weight_ranges": {
      "range": {
        "[1]": "weight",
        "[2]": [
          { "to": 50 },
          { "from": 50 }
        ]
      }
    }
  },
  "size": 0
}
Drag options to blanks, or click blank then click option'
Afield
Branges
Cbuckets
Dvalues
Attempts:
3 left
💡 Hint
Common Mistakes
Using "buckets" or "values" instead of "ranges" causes errors.
Swapping the keys "field" and "ranges" is invalid.
5fill in blank
hard

Fill all three blanks to create a range bucket aggregation on "temperature" with buckets for below 0, 0 to 30, and above 30, and add a sub-aggregation "max_temp" to find the maximum temperature in each bucket.

Elasticsearch
{
  "aggs": {
    "temp_ranges": {
      "range": {
        "[1]": "temperature",
        "[2]": [
          { "to": 0 },
          { "from": 0, "to": 30 },
          { "from": 30 }
        ]
      },
      "aggs": {
        "max_temp": {
          "[3]": {
            "field": "temperature"
          }
        }
      }
    }
  },
  "size": 0
}
Drag options to blanks, or click blank then click option'
Afield
Branges
Cmax
Davg
Attempts:
3 left
💡 Hint
Common Mistakes
Using "avg" instead of "max" for the sub-aggregation.
Swapping "field" and "ranges" keys.
Omitting the sub-aggregation key.