restrict spark index to maximum value