简体   繁体   中英

Elasticsearch Date_Histogram does not cover entire filter

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

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
            }
         }
      }
   }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM