Create weekday barchart from timestamp

Hi,

I am trying to create a bar chart where I have both the average documents count per day of the week (eg Monday to Sunday) over the entire period and the documents count over the current week.
So far I have only managed to query the total documents count per day of the week (see query below) but I don't know how to create the visualization.

POST /myindex/_search?size=0
{
  "query":{
    "match_all": {}
  },
    "aggs": {
        "dayOfWeek": {
            "terms": {
                "script": {
                    "lang": "painless",
                    "source": "doc['date'].value.dayOfWeek"
                }
            }
        }
    }
}

The result I would like to obtain is as follows:
image

Thanks for you help

Hey @OlivierV, you'll want to start by creating a Kibana scripted field for the dayOfWeek, and then you can create a Vertical Bar Chart with the following configuration:

Make sure that you include the "JSON Input" sections, to get gaps to be reflected right in the averages.

Thanks it worked!

I just have one more issue which is UI related: how can I map the day_of_week values (eg 1 to 7) to string values Monday to Sunday on the chart?

Hey @OlivierV, I'd recommend changing your scripted field to return the string of Monday to Sunday. There isn't away via Kibana's Visualize to perform this translation at the moment.

Yeah that's what I've tried but then it messes the way days are ordered like it orders them alphabetically

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.