My case is as follows, I am conducting a search for sales that occurred between 2021-12-23 to 2022-01-23, and I need to know the total sales by day of the week, regardless of the week and year.
So I can theoretically know which day of the week has the most sales.
For this I used the Date Histogram, however, it does not group the results by day of the week, bringing the day of the week and the total sales in a formatted way.
How do I gather all sales per day, regardless of the week?
Code:
{
"_source": false,
"stored_fields": "_none_",
"aggs": {
"sales_over_dayofweek": {
"date_histogram": {
"field": "date",
"format": "e",
"interval": "day"
}
}
}
}
Result:
"aggregations": {
"sales_over_dayofweek": {
"buckets": [
{
"key_as_string": "5",
"key": 1642118400000,
"doc_count": 1
},
{
"key_as_string": "6",
"key": 1642204800000,
"doc_count": 0
},
{
"key_as_string": "7",
"key": 1642291200000,
"doc_count": 0
},
{
"key_as_string": "1",
"key": 1642377600000,
"doc_count": 0
},
{
"key_as_string": "2",
"key": 1642464000000,
"doc_count": 0
},
{
"key_as_string": "3",
"key": 1642550400000,
"doc_count": 1
},
{
"key_as_string": "4",
"key": 1642636800000,
"doc_count": 0
},
{
"key_as_string": "5",
"key": 1642723200000,
"doc_count": 3
}
]
}
}