【问题标题】:Is there a way to convert a date field into a different timezone using Painless language?有没有办法使用无痛语言将日期字段转换为不同的时区?
【发布时间】:2019-01-16 10:44:50
【问题描述】:

有没有办法使用 Painless 转换此代码? 索引有一个名为 created 的字段,目标是将值转换为不同的时区,目前是 UTC。

  "aggregations": {
    "dayOfWeek": {
      "terms": {
        "script": {
          "inline": "doc['created'].date.setZone(org.joda.time.DateTimeZone.forID(tz)); doc['created'].date.dayOfWeek",
          "lang": "groovy",
          "params": {
            "tz": "Europe/London"
          }
        }
      }
    }
  }

【问题讨论】:

  • 它是否有效?运行此程序时是否出现任何错误?
  • 我认为它工作正常。我没有安装 groovy,我只有 painless。所以我试图找到一种使用 painless 的方法。

标签: elasticsearch timezone elasticsearch-painless


【解决方案1】:

根据我自己的需要在谷歌上进行了长时间的搜索。 这对我有用(使用无痛):

def myDate = doc['created'].value.withZoneSameInstant(ZoneId.of('Europe/London')); 
myDate.dayOfWeek;

我在此页面上找到了帮助: https://gitlab.kveer.fr/upstream/elasticsearch/commit/81f60652d8c4763b3470d148239c96bcd0c29553

【讨论】:

  • 太棒了!这让我很开心.. 已经找了几天了,最后他的 sn-p 工作了!谢谢。
猜你喜欢
  • 2011-08-18
  • 1970-01-01
  • 2016-08-29
  • 2018-08-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多