将时间调整到时区

Get time adjusted to timezone

我的 Elasticsearch 文档中有一个日期字段。 我在那个领域聚合。

这是我的查询

GET _search
{
    "size": 0, 
   "aggregations": {
  "timeslice": {
     "histogram": {
        "script": "doc['ad_inTime'].date.getHourOfDay()",
        "interval": 1,
        "min_doc_count": 0,
        "extended_bounds": {
           "min": 0,
           "max": 23
        },
        "order": {
           "_key": "desc"
        },
        "offset":0
     }
  }
 }
}

现在我想在此行中传递时区信息(偏移量或时区名称 - 无论哪个有效):

"script": "doc['ad_inTime'].date.getHourOfDay()",

并将日期调整为 timezone.Is 有什么办法吗?

您可以像这样将时区作为参数传递给您的脚本:

{
  "size": 0,
  "aggregations": {
    "timeslice": {
      "histogram": {
        "script": {
          "inline": "doc['openDate'].date.setZone(DateTimeZone.forID(tz)); doc['openDate'].date.getHourOfDay()",
          "params": {
            "tz": "Europe/London"
          }
        },
        "interval": 1,
        "min_doc_count": 0,
        "extended_bounds": {
          "min": 0,
          "max": 23
        },
        "order": {
          "_key": "desc"
        },
        "offset": 0
      }
    }
  }
}