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:
-
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. -
Next, Kibana will ask you to choose the visualization type. For this job, select
Pie
. -
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_*
. -
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”. -
On the “Aggregation” drop-down, select
Terms
. For "Field", choosegenre.keyword
. Lastly, hit theApply
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.
-
Head to
Visualize
and click on the+ Create Visualization
button. -
From the list of visualization types, select
Vertical bar
. -
Choose the index pattern that matches your movie data index.
-
Now, for
Y-axis
, selectCount
as this is the value we wish to visualize. -
For
X-axis
, select theDate Histogram
aggregation and set the field torelease_year.keyword
. Finally, click onApply
.
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.
-
Create a new visualization and pick
Heat Map
from the list. -
Select the appropriate movie data index pattern.
-
To
Metric
, selectAverage
and set the field torating
. -
Now, fill
Buckets
by selectingSplit Chart
then set aggregation toDate Histogram
and field torelease_year.keyword
. -
Finally, add another bucket by clicking
Add sub-buckets
. Set theSub Aggregation
toTerms
and theField
torating.keyword
. Remember to clickApply
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