Aggregate Data in Elasticsearch

2 hours
  • 3 Learning Objectives

About this Hands-on Lab

Elasticsearch’s searching capabilities extend far beyond simple text searches. Elasticsearch is a powerful analytics engine that can perform complex aggregations, including nested and pipelined aggregations. Using aggregations in Elasticsearch, you can begin to unlock the full potential of Elasticsearch’s analytics capabilities. In this hands-on lab, you will answer series of questions using bucket, metric, and pipeline aggregations.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create an aggregation to answer question 1.

Use the Kibana console tool to execute the following:

GET bank/_search
{
  "size": 0,
  "aggs": {
    "employers": {
      "cardinality": {
        "field": "employer.keyword"
      }
    }
  }
}
Create an aggregation to answer question 2.

Use the Kibana console tool to execute the following:

GET bank/_search
{
  "size": 0,
  "aggs": {
    "state": {
      "terms": {
        "field": "state.keyword",
        "size": 50
      }
    }
  }
}
Create an aggregation to answer question 3.

Use the Kibana console tool to execute the following:

GET bank/_search
{
  "size": 0,
  "aggs": {
    "state": {
      "terms": {
        "field": "state.keyword",
        "size": 50
      },
      "aggs": {
        "balance": {
          "avg": {
            "field": "balance"
          }
        }
      }
    },
    "max_average_balance": {
      "max_bucket": {
        "buckets_path": "state>balance"
      }
    }
  }
}

Additional Resources

You work as a data analyst for an online banking company that uses a 3-node Elasticsearch cluster as a NoSQL database for active accounts. You have been asked to determine the answers to a series of questions using the Elasticsearch search API. Your searches should not return any documents and should only provide the aggregation result.

  1. How many unique employers are there among our account holders?
  2. How many accounts do we have in each of the 50 US states?
  3. What is the average balance for each of the 50 US states, and what state has the maximum average balance?

Your master-1 node has an Kibana instance which can be accessed in your local web browser by navigating to the public IP address of the master-1 node over port 8080 (example: http://public_ip:8080). To log in, use the elastic user with the password elastic_566.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?