public static string GetIndexForTimeRange(long fromTicksUtc, long toTicksUtc) { var stringBuilder = new StringBuilder(); var time = DateTimeFormatter.DateFromTicks(fromTicksUtc); var endTime = DateTimeFormatter.DateFromTicks(toTicksUtc).Add(minimumSupportedIndexCreationInterval); var dayWildcardFormat = RtqElasticsearchConsts.DataIndexNameFormat.Replace("dd", "*"); var monthWildcardFormat = dayWildcardFormat.Replace("MM", "*"); while (time < endTime) { var moved = false; if (time.Day == 1) { DateTime nextTime; if (time.Month == 1) { if ((nextTime = time.AddYears(1)) <= endTime) { Append(stringBuilder, time, monthWildcardFormat); time = nextTime; moved = true; } } if (!moved && (nextTime = time.AddMonths(1)) <= endTime) { Append(stringBuilder, time, dayWildcardFormat); time = nextTime; moved = true; } } if (!moved) { Append(stringBuilder, time, RtqElasticsearchConsts.DataIndexNameFormat); time = time.AddDays(1); } } return(stringBuilder.ToString()); }