This website uses cookies to enhance the user experience

Visualize: Creating Charts and Visualizations

Share:

In this tutorial, we are going to explore Kibana's Visualize option, which is a real gem when it comes to creating data visualizations from Elasticsearch data. Through Kibana, you can create bar charts, histograms, pie charts, and several other types of fascinating visualizations.

First, let's understand what Kibana is. Kibana is an open-source data visualization and exploration tool from Elastic stack (often called ELK stack, stands for Elasticsearch, Logstash, Kibana). It allows you to visualize Elasticsearch data and navigate the Elastic Stack for deep insights.

Before diving into creating visualizations, ensure that your Elasticsearch and Kibana are properly set up and you've some data indexed in Elasticsearch. For this tutorial, let's assume we have a movie database that contains information like the release year, genre, ratings, director, and many more.

Creating a Pie Chart

Our first task will be to create a pie chart that represents the number of films in each genre. To create our first visualization, follow these steps:

  1. Open your Kibana instance and click on Visualize in the left-hand navigation menu. If it's your first time using this feature, you will see a welcome screen. Click on the + Create Visualization button.

  2. Next, Kibana will ask you to choose the visualization type. For this job, select Pie.

  3. After selecting the visualization type, you will need to choose the index pattern. Select the one that matches your movie data index. In this case, we might select movies_*.

  4. After picking the index pattern, you will be taken to a new screen where you can configure the visualization. Make sure the buckets section is in focus by clicking on it. Afterward, click on “Split slices”.

  5. On the “Aggregation” drop-down, select Terms. For "Field", choose genre.keyword. Lastly, hit the Apply button.

Your code to achieve these steps will be similar to the one below.

{
  "aggs": {
    "genre_count": {
      "terms": {
        "field": "genre.keyword"
      }
    }
  },
  "size": 0
}

This command counts the number of documents that fall into each bucket and by setting the size to 0, we are asking Elasticsearch to return the aggregations only.

Creating a Bar Chart

Let's now turn our attention to a different type of Kibana visualization: bar charts. For this task, we would display the number of movies released each year.

  1. Head to Visualize and click on the + Create Visualization button.

  2. From the list of visualization types, select Vertical bar.

  3. Choose the index pattern that matches your movie data index.

  4. Now, for Y-axis, select Count as this is the value we wish to visualize.

  5. For X-axis, select the Date Histogram aggregation and set the field to release_year.keyword. Finally, click on Apply.

Here is a sample code snippet for the task.

{
  "aggs": {
    "movies_per_year": {
      "date_histogram": {
        "field": "release_year.keyword",
        "interval": "year"
      }
    }
  },
  "size": 0
}

Creating a Heat Map

Heatmaps, which present data in shades or colors, are excellent for spotting trends within datasets. Let's create a heatmap, using our movie data, that shows the movie ratings across different years.

  1. Create a new visualization and pick Heat Map from the list.

  2. Select the appropriate movie data index pattern.

  3. To Metric, select Average and set the field to rating.

  4. Now, fill Buckets by selecting Split Chart then set aggregation to Date Histogram and field to release_year.keyword.

  5. Finally, add another bucket by clicking Add sub-buckets. Set the Sub Aggregation to Terms and the Field to rating.keyword. Remember to click Apply at the end.

Here's a snapshot of what the request in Elasticsearch would look like:

{
  "aggs": {
    "average_rating": {
      "avg": {
        "field": "rating"
      }
    },
    "movies_per_year": {
      "date_histogram": {
        "field": "release_year.keyword",
        "interval": "year"
      },
      "aggs": {
        "rating_distribution": {
          "terms": {
            "field": "rating.keyword",
            "size": 5
          }
        }
      }
    }
  },
  "size": 0
}

In conclusion, Kibana's Visualize feature makes creating charts and visualizations a breeze, even for large datasets. It provides an intuitive interface and a wide variety of visualization options, enabling you to present your data as per your convenience and requirements.

0 Comment


Sign up or Log in to leave a comment


Recent job openings

Australia, Brisbane, QLD

Remote

Full-time

SQL

SQL

posted 20 hours ago

Japan, Tokyo, Tokyo

Remote

Full-time

posted 20 hours ago

Lebanon, Beirut, Beirut Governorate

Remote

Full-time

JavaScript

JavaScript

TypeScript

TypeScript

+5

posted 20 hours ago

United States, Fort Worth, TX

Remote

Full-time

Python

Python

Java

Java

+11

posted 20 hours ago

India, Gurugram, HR

Remote

Python

Python

Rust

Rust

+8

posted 21 hours ago