通过下面的汇总并使用ES5,我想基于给定的时区(从TZ数据库提供作为标识符)获取dayOfWeek和hourOfDay。
如何编辑"doc['created'].date.dayOfWeek'以调整偏移量?
"doc['created'].date.dayOfWeek'
aggs: { dayOfWeek: { terms: { script: { inline: "doc['created'].date.dayOfWeek", lang: 'painless', }, }, aggs: { hourOfDay: { terms: { script: { inline: "doc['created'].date.hourOfDay", lang: 'painless', }, }, }, }, }, },
这样的事情应该起作用:
{ "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的内联脚本。请参阅:此讨论。
script.engine.groovy.inline.aggs: on
注意。上面的内容无法正常工作,因为它已被锁定,并且不允许您编辑白名单。。