{"id":15081,"date":"2017-09-04T11:25:01","date_gmt":"2017-09-04T09:25:01","guid":{"rendered":"https:\/\/blog.trifork.com\/?p=15081"},"modified":"2017-09-04T11:25:01","modified_gmt":"2017-09-04T09:25:01","slug":"kibana-histogram-on-day-of-week","status":"publish","type":"post","link":"https:\/\/trifork.nl\/blog\/kibana-histogram-on-day-of-week\/","title":{"rendered":"Kibana Histogram on Day of Week"},"content":{"rendered":"<p>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:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-first-visualization.png\" alt=\"\" width=\"1920\" height=\"1080\" class=\"alignnone size-full wp-image-15082\" srcset=\"https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-first-visualization.png 1920w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-first-visualization-300x169.png 300w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-first-visualization-1024x576.png 1024w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-first-visualization-768x432.png 768w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-first-visualization-1536x864.png 1536w\" sizes=\"auto, (max-width: 1920px) 100vw, 1920px\" \/><\/p>\n<p><!--more--><\/p>\n<p>Luckily, using the Painless scripting language, I can add a scripted field to my &#8216;index&#8217;. I am not really adding it to my Elasticsearch index. I am adding it to Kibana&#8217;s view of the index. Under &#8220;Management&#8221;, &#8220;Index Patterns&#8221; and &#8220;scripted fields&#8221;, I can add a Painless script that will generate the content of the field.<\/p>\n<p>I use <code>doc['timestamp'].date.dayOfWeek<\/code> to get a numeral representation of the day of the week: 1 for Monday, 7 for Sunday:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-scripted-field.png\" alt=\"\" width=\"1855\" height=\"1056\" class=\"alignnone size-full wp-image-15085\" srcset=\"https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-scripted-field.png 1855w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-scripted-field-300x171.png 300w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-scripted-field-1024x583.png 1024w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-scripted-field-768x437.png 768w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-scripted-field-1536x874.png 1536w\" sizes=\"auto, (max-width: 1855px) 100vw, 1855px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-discovery-2.png\" alt=\"\" width=\"1920\" height=\"1080\" class=\"alignnone size-full wp-image-15090\" srcset=\"https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-discovery-2.png 1920w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-discovery-2-300x169.png 300w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-discovery-2-1024x576.png 1024w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-discovery-2-768x432.png 768w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-discovery-2-1536x864.png 1536w\" sizes=\"auto, (max-width: 1920px) 100vw, 1920px\" \/><\/p>\n<p>I can now create a new visualization using a histogram instead of a date histogram:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-better-visualization.png\" alt=\"\" width=\"1920\" height=\"1080\" class=\"alignnone size-full wp-image-15092\" srcset=\"https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-better-visualization.png 1920w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-better-visualization-300x169.png 300w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-better-visualization-1024x576.png 1024w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-better-visualization-768x432.png 768w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-better-visualization-1536x864.png 1536w\" sizes=\"auto, (max-width: 1920px) 100vw, 1920px\" \/><\/p>\n<p>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).<\/p>\n<p>If I alter the scripted field to <code>doc['timestamp'].date.dayOfWeek + \" (\" + [\"\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"][doc['timestamp'].date.dayOfWeek] + \")\"<\/code>, I will be able to create a much more readable x-asis:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-readable-x-axis.png\" alt=\"\" width=\"1920\" height=\"1080\" class=\"alignnone size-full wp-image-15093\" srcset=\"https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-readable-x-axis.png 1920w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-readable-x-axis-300x169.png 300w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-readable-x-axis-1024x576.png 1024w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-readable-x-axis-768x432.png 768w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-readable-x-axis-1536x864.png 1536w\" sizes=\"auto, (max-width: 1920px) 100vw, 1920px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":89,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"content-type":"","footnotes":""},"categories":[113,15,65],"tags":[61,92,433],"class_list":["post-15081","post","type-post","status-publish","format-standard","hentry","category-axon","category-enterprise-search","category-big_data_search","tag-elasticsearch","tag-kibana","tag-painless"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Kibana Histogram on Day of Week - Trifork Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/trifork.nl\/blog\/kibana-histogram-on-day-of-week\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Kibana Histogram on Day of Week - Trifork Blog\" \/>\n<meta property=\"og:description\" content=\"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 [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/trifork.nl\/blog\/kibana-histogram-on-day-of-week\/\" \/>\n<meta property=\"og:site_name\" content=\"Trifork Blog\" \/>\n<meta property=\"article:published_time\" content=\"2017-09-04T09:25:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-first-visualization.png\" \/>\n<meta name=\"author\" content=\"Patrick Kik\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Patrick Kik\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/trifork.nl\/blog\/kibana-histogram-on-day-of-week\/\",\"url\":\"https:\/\/trifork.nl\/blog\/kibana-histogram-on-day-of-week\/\",\"name\":\"Kibana Histogram on Day of Week - Trifork Blog\",\"isPartOf\":{\"@id\":\"https:\/\/trifork.nl\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/trifork.nl\/blog\/kibana-histogram-on-day-of-week\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/trifork.nl\/blog\/kibana-histogram-on-day-of-week\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-first-visualization.png\",\"datePublished\":\"2017-09-04T09:25:01+00:00\",\"author\":{\"@id\":\"https:\/\/trifork.nl\/blog\/#\/schema\/person\/804a91e87bb08ce5fa231668f9a4f347\"},\"breadcrumb\":{\"@id\":\"https:\/\/trifork.nl\/blog\/kibana-histogram-on-day-of-week\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/trifork.nl\/blog\/kibana-histogram-on-day-of-week\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/trifork.nl\/blog\/kibana-histogram-on-day-of-week\/#primaryimage\",\"url\":\"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-first-visualization.png\",\"contentUrl\":\"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-first-visualization.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/trifork.nl\/blog\/kibana-histogram-on-day-of-week\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/trifork.nl\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Kibana Histogram on Day of Week\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/trifork.nl\/blog\/#website\",\"url\":\"https:\/\/trifork.nl\/blog\/\",\"name\":\"Trifork Blog\",\"description\":\"Keep updated on the technical solutions Trifork is working on!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/trifork.nl\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/trifork.nl\/blog\/#\/schema\/person\/804a91e87bb08ce5fa231668f9a4f347\",\"name\":\"Patrick Kik\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/trifork.nl\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/a09a7d756b544d2b48846fe320107ebc?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/a09a7d756b544d2b48846fe320107ebc?s=96&d=mm&r=g\",\"caption\":\"Patrick Kik\"},\"url\":\"https:\/\/trifork.nl\/blog\/author\/patrickk\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Kibana Histogram on Day of Week - Trifork Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/trifork.nl\/blog\/kibana-histogram-on-day-of-week\/","og_locale":"en_US","og_type":"article","og_title":"Kibana Histogram on Day of Week - Trifork Blog","og_description":"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 [&hellip;]","og_url":"https:\/\/trifork.nl\/blog\/kibana-histogram-on-day-of-week\/","og_site_name":"Trifork Blog","article_published_time":"2017-09-04T09:25:01+00:00","og_image":[{"url":"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-first-visualization.png","type":"","width":"","height":""}],"author":"Patrick Kik","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Patrick Kik","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/trifork.nl\/blog\/kibana-histogram-on-day-of-week\/","url":"https:\/\/trifork.nl\/blog\/kibana-histogram-on-day-of-week\/","name":"Kibana Histogram on Day of Week - Trifork Blog","isPartOf":{"@id":"https:\/\/trifork.nl\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/trifork.nl\/blog\/kibana-histogram-on-day-of-week\/#primaryimage"},"image":{"@id":"https:\/\/trifork.nl\/blog\/kibana-histogram-on-day-of-week\/#primaryimage"},"thumbnailUrl":"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-first-visualization.png","datePublished":"2017-09-04T09:25:01+00:00","author":{"@id":"https:\/\/trifork.nl\/blog\/#\/schema\/person\/804a91e87bb08ce5fa231668f9a4f347"},"breadcrumb":{"@id":"https:\/\/trifork.nl\/blog\/kibana-histogram-on-day-of-week\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/trifork.nl\/blog\/kibana-histogram-on-day-of-week\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/trifork.nl\/blog\/kibana-histogram-on-day-of-week\/#primaryimage","url":"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-first-visualization.png","contentUrl":"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2017\/08\/blog-kibana-day-of-week-first-visualization.png"},{"@type":"BreadcrumbList","@id":"https:\/\/trifork.nl\/blog\/kibana-histogram-on-day-of-week\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/trifork.nl\/blog\/"},{"@type":"ListItem","position":2,"name":"Kibana Histogram on Day of Week"}]},{"@type":"WebSite","@id":"https:\/\/trifork.nl\/blog\/#website","url":"https:\/\/trifork.nl\/blog\/","name":"Trifork Blog","description":"Keep updated on the technical solutions Trifork is working on!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/trifork.nl\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/trifork.nl\/blog\/#\/schema\/person\/804a91e87bb08ce5fa231668f9a4f347","name":"Patrick Kik","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/trifork.nl\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/a09a7d756b544d2b48846fe320107ebc?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a09a7d756b544d2b48846fe320107ebc?s=96&d=mm&r=g","caption":"Patrick Kik"},"url":"https:\/\/trifork.nl\/blog\/author\/patrickk\/"}]}},"_links":{"self":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/posts\/15081","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/users\/89"}],"replies":[{"embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/comments?post=15081"}],"version-history":[{"count":0,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/posts\/15081\/revisions"}],"wp:attachment":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/media?parent=15081"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/categories?post=15081"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/tags?post=15081"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}