0

我使用 ES 5.1.2,我试图从一个date字段计算星期几和一天中的时间,并同时考虑时区。

我的第一个脚本是def d = doc['my_field'].date; d.addHours(10); d.getDayOfWeek();

错误消息是找不到 addHours() 方法

"caused_by": {
    "type": "illegal_argument_exception",
    "reason": "Unable to find dynamic method [addHours] with [1] arguments for class [org.joda.time.MutableDateTime]."
},
"script_stack": [
    "d.addHours(10); ",
    " ^---- HERE"
],

如果我将脚本更改为MutableDateTime d = doc['my_field'].date; d.addHours(10); d.getDayOfWeek();错误消息变为

"caused_by": {
  "type": "illegal_argument_exception",
  "reason": "unexpected token ['d'] was expecting one of [{<EOF>, ';'}]."
},
"script_stack": [
  "MutableDateTime d = doc['relation_denstu. ...",
  "                ^---- HERE"
],

addHours调整时区,一切都很好。但是如果我尝试动态调整时区,一切都会失败。有什么帮助吗?

4

1 回答 1

3

我也一直在为此苦苦挣扎。这适用于 Elastic 5:

GET /unittesttg1_tg1_fq1/_search
{
  "size": 0,
  "aggs": {
    "groupby": {
      "terms": {
        "script": "ZonedDateTime.ofInstant(Instant.ofEpochMilli(doc['LAST_MODIFIED_DATE'].value), ZoneId.of('+10:00')).getDayOfWeek()"          
      }
    }
  }
}
于 2017-04-12T07:14:03.380 回答