Generate Series of Days with ElasticSearch

With PostgreSQL I can use the generate_series feature to generate a list of days between two dates, and with a little effort, even generate a list of sales made by day within that range, even if there are no sales for the day, displaying the day with a value of 0.


       (SELECT COUNT(1) FROM sales WHERE = AS sales_at_day
FROM   generate_series(timestamp '2021-03-07'
                     , timestamp '2021-08-16'
                     , interval  '1 day') AS t(day);

I now have a report in Elasticsearch for the same purpose, showing sales by days within a range. I am trying to display days in results that have no sales, but this days is not displayed.

For example, if my filter is for the day 2021-03-01 / 2021-10-01, and sales will only occur between 2021-04-02 and 2021-09-01, the dates between 2021-03-01 and 2021-04 -01 do not display dates with zero values.

        "query": {
            "range": {
                "date": {
                    "from": "2020-03-01T00:00:00+0300",
                    "to": "2021-10-01T00:00:00+0300",
                    "include_lower": true,
                    "include_upper": true,
                    "boost": 1.0
        "aggs" : {
            "sales_over_time" : {
                "date_histogram" : {
                    "field" : "date",
                    "interval" : "day",
                    "min_doc_count": 0

Does Elasticsearch support this feature, or do I have to find a way to fill the result with non-existing dates?

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