# Generate Series of Days with ElasticSearch

**URL:** <https://discuss.elastic.co/t/generate-series-of-days-with-elasticsearch/288804>\
**Category:** Elasticsearch\
**Created:** [November 9, 2021, 5:47pm UTC](https://discuss.elastic.co/t/generate-series-of-days-with-elasticsearch/288804 "2021-11-09T17:47:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TomTom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tomtom/32/3676_2.png) [@TomTom](https://discuss.elastic.co/u/TomTom)\
**Post date:** [November 9, 2021, 5:47pm UTC](https://discuss.elastic.co/t/generate-series-of-days-with-elasticsearch/288804/1 "2021-11-09T17:47:40Z")

</div>

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.

Example:

```auto
SELECT t.day::date,
       (SELECT COUNT(1) FROM sales WHERE sales.date = t.day::date) 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.

```auto
{
        "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?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 7, 2021, 5:48pm UTC](https://discuss.elastic.co/t/generate-series-of-days-with-elasticsearch/288804/2 "2021-12-07T17:48:26Z")

</div>

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