0

I'm using ES Date Histogram and a weird behavior started happening and I'm wondering why.

This is the request i'm sending to elasticsearch:

{
   "from": 0,
   "size": 0,
   "query": {
      "filtered": {
         "filter": {
            "and": [
               {
                  "bool": {
                     "must": [
                        {
                           "range": {
                              "publishTime": {
                                 "from": "2010-07-02T12:15:20.000Z",
                                 "to": "2015-07-08T12:43:59.000Z"
                              }
                           }
                        }
                     ]
                  }
               }
            ]
         }
      }
   },
   "aggs": {
      "agg|date_histogram|publishTime": {
         "date_histogram": {
            "field": "publishTime",
            "interval": "1d",
            "min_doc_count": 0
         }
      }
   }
}

The result i'm getting are buckets, and the first bucket is:

{
   "key_as_string": "2010-08-24T00:00:00.000Z",
   "key": 1282608000000,
   "doc_count": 1
}

So i'm filtering from 2010-07-02 and getting results only from 2010-08-24

This is just an example, I also saw this behavior with many more missing buckets (several months).

[edit] this seems to correlate with the date of the first result, meaning that the first result in that time range is from 2010-08-24, but as I included "min_doc_count": 0 I expect to get results from that entire range

AlexD
  • 4,062
  • 5
  • 38
  • 65

1 Answers1

3

min_doc_count is only sufficient for returning empty buckets between the first and last documents matched by your filter. If you want to get results for the entire range you need to use extended_bounds as well:

  "aggs": {
      "agg|date_histogram|publishTime": {
         "date_histogram": {
            "field": "publishTime",
            "interval": "1d",
            "min_doc_count": 0
            "extended_bounds": {
                "min": 1278072920000, 
                "max": 1436359439000
            }
         }
      }
   }
Val
  • 207,596
  • 13
  • 358
  • 360