您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

在Elasticsearch中,如何将时区应用于脚本化日期操作?

在Elasticsearch中,如何将时区应用于脚本化日期操作?

这样的事情应该起作用:

{
  "size": 0,
  "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"
          }
        }
      },
      "aggs": {
        "hourOfDay": {
          "terms": {
            "script": {
              "inline": "doc['created'].date.setZone(org.joda.time.DateTimeZone.forID(tz)); doc['created'].date.hourOfDay",
              "lang": "groovy",
              "params": {
                "tz": "Europe/London"
              }
            }
          }
        }
      }
    }
  }
}

您可能需要通过添加script.engine.groovy.inline.aggs: on到elasticsearch.yml文件来启用groovy的内联脚本。请参阅:此讨论

注意。上面的内容无法正常工作,因为它已被锁定,并且不允许您编辑白名单。

其他 2022/1/1 18:13:58 有781人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶