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.