Trifork Blog

Axon Framework, DDD, Microservices

Kibana Histogram on Day of Week

September 4th, 2017 by
| Reply

I keep track of my daily commutes to and from the office. One thing I want to know is how the different days of the week are affecting my travel duration. But when indexing all my commutes into Elasticsearch, I can not (out-of-the-box) create a histogram on the day of the week. My first visualization will look like this:

Luckily, using the Painless scripting language, I can add a scripted field to my ‘index’. I am not really adding it to my Elasticsearch index. I am adding it to Kibana’s view of the index. Under “Management”, “Index Patterns” and “scripted fields”, I can add a Painless script that will generate the content of the field.

I use doc['timestamp'].date.dayOfWeek to get a numeral representation of the day of the week: 1 for Monday, 7 for Sunday:

I can now create a new visualization using a histogram instead of a date histogram:

But there is still something I can improve. The days of the week are now called 1 through 5 (not 7, because I generally do not commute in weekends).

If I alter the scripted field to doc['timestamp'].date.dayOfWeek + " (" + ["", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"][doc['timestamp'].date.dayOfWeek] + ")", I will be able to create a much more readable x-asis:

Leave a Reply