Using missing_bucket with a composite aggregation with a date_histogram source doesn't seem to create missing buckets

Using missing_bucket with a composite aggregation with a date_histogram source doesn't seem to create missing buckets. In the example below, 2 documents are created with a date field that are 45 minutes apart. Using a composite aggregation date_histogram source with a fixed_interval set to 15m the expected outcome should be 3 buckets, one for each 15 minute interval with the interval in the middle containing 0 doc_count. Instead only the first and last 15 minute intervals are present in the response. Please review my example to confirm the bug.

Enter the following in a Kibana console to reproduce the problem:

  1. Create index with date mapping for time field
PUT /test
{
  "mappings": {
    "properties": {
      "myDate":    { "type": "date" }
    }
  }
}
  1. Add test data
PUT /test/_doc/1
{
  "myDate": "2020-08-03T15:00:00"
}

PUT /test/_doc/2
{
  "myDate": "2020-08-03T15:45:00"
}
  1. Create composite aggregation with date histogram with 15 minute intervals
GET /test/_search
{
  "size": 0,
  "query": {
    "match_all": {}
  },
  "aggregations": {
    "intervals": {
      "composite": {
        "sources": [
          {
            "test_date_histogram": {
              "date_histogram": {
                "field": "myDate",
                "fixed_interval": "15m",
                "missing_bucket": true
              }
            }
          }
        ]
      }
    }
  }
}

Response from Kibana console:

{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  },
  "aggregations" : {
    "intervals" : {
      "after_key" : {
        "test_date_histogram" : 1596469500000
      },
      "buckets" : [
        {
          "key" : {
            "test_date_histogram" : 1596466800000
          },
          "doc_count" : 1
        },
        {
          "key" : {
            "test_date_histogram" : 1596469500000
          },
          "doc_count" : 1
        }
      ]
    }
  }
}

Elasticsearch/Kibana version: 7.4.2
Java version: openjdk version "12.0.2" 2019-07-16
OS version: Windows 10 Professional

Tried the same example with the same result in Elasticsearch/Kibana version 7.8.1

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