Build your own dashboard

Want to load some data into Kibana and build a dashboard? This tutorial shows you how to:

When you complete this tutorial, you’ll have a dashboard that looks like this.

tutorial dashboard

Load sample data

This tutorial requires you to download three data sets:

  • The complete works of William Shakespeare, suitably parsed into fields
  • A set of fictitious accounts with randomly generated data
  • A set of randomly generated log files

Download the data sets

Create a new working directory where you want to download the files. From that directory, run the following commands:

  1. curl -O https://download.elastic.co/demos/kibana/gettingstarted/8.x/shakespeare.json
  2. curl -O https://download.elastic.co/demos/kibana/gettingstarted/8.x/accounts.zip
  3. curl -O https://download.elastic.co/demos/kibana/gettingstarted/8.x/logs.jsonl.gz

Two of the data sets are compressed. To extract the files, use these commands:

  1. unzip accounts.zip
  2. gunzip logs.jsonl.gz

Structure of the data sets

The Shakespeare data set has this structure:

  1. {
  2. "line_id": INT,
  3. "play_name": "String",
  4. "speech_number": INT,
  5. "line_number": "String",
  6. "speaker": "String",
  7. "text_entry": "String",
  8. }

The accounts data set is structured as follows:

  1. {
  2. "account_number": INT,
  3. "balance": INT,
  4. "firstname": "String",
  5. "lastname": "String",
  6. "age": INT,
  7. "gender": "M or F",
  8. "address": "String",
  9. "employer": "String",
  10. "email": "String",
  11. "city": "String",
  12. "state": "String"
  13. }

The logs data set has dozens of different fields. Here are the notable fields for this tutorial:

  1. {
  2. "memory": INT,
  3. "geo.coordinates": "geo_point"
  4. "@timestamp": "date"
  5. }

Set up mappings

Before you load the Shakespeare and logs data sets, you must set up mappings for the fields. Mappings divide the documents in the index into logical groups and specify the characteristics of the fields. These characteristics include the searchability of the field and whether it’s tokenized, or broken up into separate words.

If security is enabled, you must have the all Kibana privilege to run this tutorial. You must also have the create, manage read, write, and delete index privileges. See Security privileges for more information.

Open Dev Tools. On the Console page, set up a mapping for the Shakespeare data set:

  1. PUT /shakespeare
  2. {
  3. "mappings": {
  4. "properties": {
  5. "speaker": {"type": "keyword"},
  6. "play_name": {"type": "keyword"},
  7. "line_id": {"type": "integer"},
  8. "speech_number": {"type": "integer"}
  9. }
  10. }
  11. }

This mapping specifies field characteristics for the data set:

  • The speaker and play_name fields are keyword fields. These fields are not analyzed. The strings are treated as a single unit even if they contain multiple words.
  • The line_id and speech_number fields are integers.

The logs data set requires a mapping to label the latitude and longitude pairs as geographic locations by applying the geo_point type.

  1. PUT /logstash-2015.05.18
  2. {
  3. "mappings": {
  4. "properties": {
  5. "geo": {
  6. "properties": {
  7. "coordinates": {
  8. "type": "geo_point"
  9. }
  10. }
  11. }
  12. }
  13. }
  14. }
  1. PUT /logstash-2015.05.19
  2. {
  3. "mappings": {
  4. "properties": {
  5. "geo": {
  6. "properties": {
  7. "coordinates": {
  8. "type": "geo_point"
  9. }
  10. }
  11. }
  12. }
  13. }
  14. }
  1. PUT /logstash-2015.05.20
  2. {
  3. "mappings": {
  4. "properties": {
  5. "geo": {
  6. "properties": {
  7. "coordinates": {
  8. "type": "geo_point"
  9. }
  10. }
  11. }
  12. }
  13. }
  14. }

The accounts data set doesn’t require any mappings.

Load the data sets

At this point, you’re ready to use the Elasticsearch bulk API to load the data sets:

  1. curl -u elastic -H 'Content-Type: application/x-ndjson' -XPOST '<host>:<port>/bank/_bulk?pretty' --data-binary @accounts.json
  2. curl -u elastic -H 'Content-Type: application/x-ndjson' -XPOST '<host>:<port>/shakespeare/_bulk?pretty' --data-binary @shakespeare.json
  3. curl -u elastic -H 'Content-Type: application/x-ndjson' -XPOST '<host>:<port>/_bulk?pretty' --data-binary @logs.jsonl

Or for Windows users, in Powershell:

  1. Invoke-RestMethod "http://<host>:<port>/bank/account/_bulk?pretty" -Method Post -ContentType 'application/x-ndjson' -InFile "accounts.json"
  2. Invoke-RestMethod "http://<host>:<port>/shakespeare/_bulk?pretty" -Method Post -ContentType 'application/x-ndjson' -InFile "shakespeare.json"
  3. Invoke-RestMethod "http://<host>:<port>/_bulk?pretty" -Method Post -ContentType 'application/x-ndjson' -InFile "logs.jsonl"

These commands might take some time to execute, depending on the available computing resources.

Verify successful loading:

  1. GET /_cat/indices?v

Your output should look similar to this:

  1. health status index pri rep docs.count docs.deleted store.size pri.store.size
  2. yellow open bank 1 1 1000 0 418.2kb 418.2kb
  3. yellow open shakespeare 1 1 111396 0 17.6mb 17.6mb
  4. yellow open logstash-2015.05.18 1 1 4631 0 15.6mb 15.6mb
  5. yellow open logstash-2015.05.19 1 1 4624 0 15.7mb 15.7mb
  6. yellow open logstash-2015.05.20 1 1 4750 0 16.4mb 16.4mb

Most Popular