[BZ 1104888] fix bucket aggregation code for calculating max