Week of the year / sunday of the week

Week of the year is challenging when handling year rolling, etc. a previous article was:
Week of the year aggregations using Painless - Elastic Stack / Elasticsearch - Discuss the Elastic Stack

I found a simple solution to this problem, rather trying tog et week of the year, i decided to standardize on the "sunday of the week" this avoids all sorts of issue with leap years, rolling years, etc. its also a very simple script.

doc['@timestamp'].value.plusDays(-1*(doc['@timestamp'].value.dayOfWeek)).truncatedTo(ChronoUnit.DAYS)

2 Likes

That's a great solution, thank you!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.