I'm really struggling with this. In Painless, how would I update the following:
"aggs": {
"total_messages_per_day_of_week": {
"terms": {
"script": {
"lang": "painless",
"source": "doc['date'].value.dayOfWeek"
}
},
To convert the UTC datetime in doc.date to a locale (e.g. 'America/Los_Angeles') BEFORE getting the day of week?
Basically I want to aggregate by day number, but where day number represents the desired timezone day, not UTC day.
Many thanks in advance!
You'd do it like this by first transforming your UTC date into a
ZonedDateTime
viaInstant.atZone()
and then taking the day of the week:And since
doc.date.value
is actuallyJodaCompatibleZonedDateTime
(i.e. a delegate ofZonedDateTime
), in your aggregation you can try this: