简体   繁体   English

Elasticsearch日期直方图存储桶从错误的日期开始

[英]Elasticsearch Date Histogram buckets starts from wrong date

I have ElasticSearch analytic query. 我有ElasticSearch分析查询。 It must aggregate sum by 7d buckets. 它必须通过7d桶汇总和。 Also I've use extended bounds. 我也使用扩展边界。 But result buckets starts from wrong date. 但结果桶从错误的日期开始。 Elastic 5.2.2 version. 弹性5.2.2版本。 What I'm doing wrong? 我做错了什么?

{
  "size": 0,
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "doc.dateExecute": {
              "from": "2017-07-11",
              "to": "2017-07-31",
              "include_lower": true,
              "include_upper": true,
              "boost": 1.0
            }
          }
        }
      ],
      "disable_coord": false,
      "adjust_pure_negative": true,
      "boost": 1.0,
      "_name": "onDates"
    }
  },
  "aggregations": {
    "time": {
      "date_histogram": {
        "field": "doc.dateExecute",
        "interval": "7d",
        "offset": 0,
        "order": {
          "_key": "asc"
        },
        "keyed": false,
        "min_doc_count": 0,
        "extended_bounds": {
          "min": "2017-07-11",
          "max": "2017-07-31"
        }
      },
      "aggregations": {
        "incomingAmount": {
          "sum": {
            "field": "doc.incomingAmount"
          }
        },
        "outgoingAmount": {
          "sum": {
            "field": "doc.outgoingAmount"
          }
        }
      }
    }
  }
}

But buckets starts from "2017-07-06T00:00:00.000Z" and goes by 7d intervals to "2017-07-27T00:00:00.000Z". 但是水桶从“2017-07-06T00:00:00.000Z”开始,并且以7d间隔进入“2017-07-27T00:00:00.000Z”。 What I'm missing? 我错过了什么? Thanks! 谢谢!

Update 1 更新1

I'd try a many variants of query. 我会尝试多种查询变体。 Different timezones, ranges, disabling exteneded_bounds, intervals multiple 7 day. 不同的时区,范围,禁用exteneded_bounds,间隔7天。 It's works good only for 1-3d intervals. 它仅适用于1-3d间隔。

Ok, after some conversation on elastic forum and register a bug: 好的,在弹性论坛上进行了一些对话并注册了一个bug:

1) Working with DateHistogram and ExtendedBounds is tricky in ES (5.2 at least) DateHistogram starts buckets from UnixEpoch 1970-01-01 so if you use days intervals (like 7d or 3d etc) but need to start bucket from the left bound - you need to set offset for on date of left border (in ms). 1)在ES中使用DateHistogram和ExtendedBounds很棘手(至少5.2)DateHistogram从UnixEpoch 1970-01-01开始存储桶,所以如果你使用天间隔(如7d或3d等)但需要从左边界开始存储桶 - 你需要设置左边框日期的偏移量(以毫秒为单位)。 2) But we still have some bug on 5.2.2 version. 2)但我们仍然在5.2.2版本上有一些错误。 With 7d intervals we have explicit first bucket on Thu (01-01-1970 is Thu). 在7d的时间间隔内,我们在Thu(01-01-1970是Thu)上有明确的第一个桶。 All other buckets with proper offset. 所有其他桶具有适当的偏移量。

Lack of documentation and a lot of strange behavior :( 缺乏文档和很多奇怪的行为:(

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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