0
0
Elasticsearchquery~10 mins

Bucket aggregations (terms, histogram) 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 terms aggregation on the field "user.keyword".

Elasticsearch
{
  "aggs": {
    "users": {
      "terms": {
        "field": "[1]"
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Auser
Buser.keyword
Ckeyword.user
Dusers.keyword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the analyzed field "user" instead of the keyword subfield.
Swapping the order of "keyword" and "user" in the field name.
2fill in blank
medium

Complete the code to create a histogram aggregation on the field "price" with interval 50.

Elasticsearch
{
  "aggs": {
    "price_ranges": {
      "histogram": {
        "field": "price",
        "[1]": 50
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Arange
Bbucket_size
Cinterval
Dstep
Attempts:
3 left
💡 Hint
Common Mistakes
Using "range" instead of "interval" for histogram buckets.
Using "step" or "bucket_size" which are not valid parameters.
3fill in blank
hard

Fix the error in the terms aggregation by completing the missing parameter to limit the number of buckets to 5.

Elasticsearch
{
  "aggs": {
    "top_users": {
      "terms": {
        "field": "user.keyword",
        "[1]": 5
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Amax_buckets
Blimit
Ccount
Dsize
Attempts:
3 left
💡 Hint
Common Mistakes
Using "limit" or "count" which are not valid parameters for terms aggregation.
Using "max_buckets" which is a cluster setting, not an aggregation parameter.
4fill in blank
hard

Fill both blanks to create a histogram aggregation on "age" with interval 10 and include only buckets with doc_count greater than 5.

Elasticsearch
{
  "aggs": {
    "age_histogram": {
      "histogram": {
        "field": "age",
        "[1]": 10
      },
      "aggs": {
        "filtered_buckets": {
          "bucket_selector": {
            "buckets_path": {
              "count": "_count"
            },
            "script": "params.count [2] 5"
          }
        }
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Ainterval
B>
C<
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using "range" instead of "interval" for histogram.
Using "<" or "==" in the script which would filter incorrectly.
5fill in blank
hard

Fill all three blanks to create a nested aggregation: a terms aggregation on "category.keyword", with a sub-aggregation histogram on "price" with interval 20, and limit the terms buckets to 3.

Elasticsearch
{
  "aggs": {
    "categories": {
      "terms": {
        "field": "[1]",
        "[2]": 3
      },
      "aggs": {
        "price_ranges": {
          "histogram": {
            "field": "price",
            "[3]": 20
          }
        }
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Acategory.keyword
Bsize
Cinterval
Dprice.keyword
Attempts:
3 left
💡 Hint
Common Mistakes
Using "price.keyword" for histogram field instead of "price".
Using "limit" instead of "size" to limit terms buckets.