Unable to show empty buckets when using Date Histogram on @timestamp field

Hi Team,

I am retrieving results of a query for last 7 days in visualisation, but in the response i am not seeing results for empty buckets i.e its not showing any result for that day when there is no data. There is no option to choose as Show empty buckets.

In below graph, it shows all the dates of last 7 days (even if its having any result or not) but in response i am only getting dates that are having any result and not all the dates which are having zero results also. How can i change this to get all the dates (irrespective of zero or any result) in response.

Below is the response - Its not showing 17th, 18th date and 20th date

  "took": 6,
  "timed_out": false,
  "_shards": {
    "total": 21,
    "successful": 21,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 13,
    "max_score": null,
    "hits": []
  },
  "aggregations": {
    "2": {
      "buckets": [
        {
          "key_as_string": "2021-07-15T00:00:00.000+05:30",
          "key": 1626287400000,
          "doc_count": 1
        },
        {
          "key_as_string": "2021-07-16T00:00:00.000+05:30",
          "key": 1626373800000,
          "doc_count": 7
        },
        {
          "key_as_string": "2021-07-19T00:00:00.000+05:30",
          "key": 1626633000000,
          "doc_count": 4
        },
        {
          "key_as_string": "2021-07-21T00:00:00.000+05:30",
          "key": 1626805800000,
          "doc_count": 1
        }
      ]
    }
  },
  "status": 200
}

version is 7.4

Thanks,

Try using the below in your advanced JSON input

{ "min_doc_count": 0 }

And see if you can get what you wanted.

Hi @Sandeep_Raju, Thanks for your reply.

Yes i have tried this in devtools by changing request as "min_doc_count": 1 to "min_doc_count": 0 and getting all seven days results. Thanks.

but same is not working when checking for 24 hrs of a day i.e its not showing all the hrs irrespective of results. only shows hr that has any result. Any idea why?

Thanks,

Can you try to keep minimum interval as auto in date histogram instead of daily and check?

Hi @Sandeep_Raju,

I am getting below response as expected for 7 days (i.e In response, getting each date with their whatever results is whether 0 or any number) after changing above min_doc_count: 0, this was for 7 days.

{
          "key_as_string" : "2021-07-15T00:00:00.000+05:30",
          "key" : 1626287400000,
          "doc_count" : 1
        },
        {
          "key_as_string" : "2021-07-16T00:00:00.000+05:30",
          "key" : 1626373800000,
          "doc_count" : 7
        },
        {
          "key_as_string" : "2021-07-17T00:00:00.000+05:30",
          "key" : 1626460200000,
          "doc_count" : 0
        },
        {
          "key_as_string" : "2021-07-18T00:00:00.000+05:30",
          "key" : 1626546600000,
          "doc_count" : 0
        },
        {
          "key_as_string" : "2021-07-19T00:00:00.000+05:30",
          "key" : 1626633000000,
          "doc_count" : 4
        },
        {
          "key_as_string" : "2021-07-20T00:00:00.000+05:30",
          "key" : 1626719400000,
          "doc_count" : 0
        },
        {
          "key_as_string" : "2021-07-21T00:00:00.000+05:30",
          "key" : 1626805800000,
          "doc_count" : 1
        }

Now, I am trying to get results of all 24 hrs of a day by changing timerange from Last 7 days to Last 24 hours and minimum interval as Auto but it's still not showing for all 24 hrs.

Thanks,