Warning: This feature is in beta and is subject to change. The design and code are less mature than the formal GA functionality and are provided as-is without warranty. Beta functionality is not subject to the support SLA of official GA functionality. This feature is available in version 7.11 and later.

URL template input uses Handlebars, a simple templating language. A Handlebars template looks like regular text with an embedded Handlebars expression.

https://github.com/elastic/kibana/issues?q={{event.value}}
Copy the code

Above, we can add Spaces to {{}} to make it easier to read. The Handlebars expression is {{, something followed by}}. When driller down is performed, these expressions are replaced with values in the dashboard and interaction context.

The URL template contains the following three parts:

  • Handlebars
  • Variables
  • Helpers

In today’s exercise, I’ll show you how to use some of the variables and helpers above to complete drilldown in the Kibana dashboard. In today’s exercise I will use Elasticsearch 7.11 to demonstrate.

 

To prepare data

We can download the prepared data from Github:

git clone https://github.com/liu-xiao-guo/kibana-drilldown-dataset
Copy the code

In the repository above, there is a file called ratings_small.csv. This data is the actual data of the cinema IMDB. If you’re interested, you can download it at kaggle.com. Its file format is as follows:

rating_small.csv

UserId, movieId, rating, timestamp,31,2.5 1, 1260759144, 1102, 9,3.0, 1260759179 1106 1,3.0, 1260759182, 1112, 9,2.0, 1260759185Copy the code

You can import data into Elasticsearch as follows.

 

Let’s select the ratings_small.csv file we just downloaded.

Notice above that we need to change the type of timestamp to date. We click the Import button. Let’s create an index pattern for movies indexes:

We select TIMESTAMP as the Time field. Click Create Index Pattern above. So we create movies Index Pattern. We can see the imported data in Discover:

From the data above, we can see the data from January 11, 1970 to January 18, 1970.

 

Create a Dashboard

Based on the above data, let’s create two visualizations:

Save the above visualization as Movies per Day. Similarly, we create another visualization that looks like this:

On the X-axis we have the movieID, and on the Y-axis we have the quantity.

Let’s add the two visualizations above to our Movies Dashboard:

 

So we’ve created Dashboard.

 

Create range Selection drilldown

In the first visualization above, we want to drilldown against the time range of the visualization, that is, we want to search against imDB over the time period shown in the visualization. We can do this in the following way.

We put in the following URL template:

https://www.imdb.com/search/title/?release_date={{date event.from "YYYY-MM-DD"}},{{date event.to "YYYY-MM-DD"}}
Copy the code

Above, we use event.from and event.to to get the time range, and also use date Helper to convert the format. Click the Create Drilldown button:

Save the current Dashboard. When we click on the white space of the visualization, we see a menu:

Click on IMDB Movie Search:

From the above we can see that the corresponding query results can be found on the IMDB page. In the address bar, we can see the time range displayed.

 

Queries for X-axis or Y-axis

In many cases, we might want to drilldown the X-axis content, so how do we do that? Let’s create a drilldown against the Movies Totals visualization:

In the URL template above, we enter the following:

https://imdb.com/find?q={{event.points.[0].value}}
Copy the code

Maybe this isn’t a great example, but the point here is that event.points.[0]. Value gets the value on the X axis and the value on the Y axis is event.points. Click Create Drilldown and save the current Dashboard:

We can see that q=356 up here, 356 here is the X-axis value of the current click point.

 

Helper example

In the example above, we have shown how to use the Date Helper to format the time. In the following examples, I’ll show a few more concrete examples to show how helper can be used. We start by creating a player index:

POST players/_bulk { "index" : { "_id" : "1" } } { "Player" : "Lebron James", "Team": "Cavaliers", "Season": "2005", "PlayerID" : "2544", "AveragePTS" : 30.792} {" index ": {" _id" : "2"}} {" Player ":" Kobe Bryant ", "Team" : "Lakers", "Lakers", "Season": "2005", "PlayerID": "977", "AveragePTS": 33.737}Copy the code

We next need to create an index schema for this index and create a table visualization. If you don’t know how to do this visualization, see the previous article “Kibana: Creating links to Drilldown-7.11 version for table”.

We can use Lens to create a table like the one shown above. Let’s put this table into a Dashboard:

Now let’s create some drilldowns.

Above, we fill the URL template with:

http://www.nba.com/{{lowercase event.value}}
Copy the code

Above, we used lowercase to change the click value to lowercase and pass it into the NBA web page for query. Click on the Create the drilldown:

It shows that Drilldown has been created. Save the current Dashboard:

Next, let’s take a look at each athlete. We create a drilldown for table row click:

Above, we type in the URL templagte:

http://www.nba.com/player/{{ event.values.[3] }}/{{lowercase (replace event.values.[0] " " "-")}}
Copy the code

Above, we use replace to replace the Spaces in the name with a – symbol, and then lowercase to make the letters lowercase. Click Create Drilldown above and save the current Dashboard:

From above, we can see the information of the athlete.