Adjust to include leading zero in front of date regex.

This commit is contained in:
amandahla 2016-11-01 15:26:56 -02:00
parent c6ac0bc6af
commit 265be4e09d
2 changed files with 4 additions and 4 deletions

View File

@ -77,9 +77,9 @@ func (a *Elasticsearch) Connect() error {
year := strconv.Itoa(time.Now().Year()) year := strconv.Itoa(time.Now().Year())
a.IndexName = strings.Replace(a.IndexName, "%Y", year, -1) a.IndexName = strings.Replace(a.IndexName, "%Y", year, -1)
a.IndexName = strings.Replace(a.IndexName, "%y", year[len(year)-2:], -1) a.IndexName = strings.Replace(a.IndexName, "%y", year[len(year)-2:], -1)
a.IndexName = strings.Replace(a.IndexName, "%m", strconv.Itoa(int(time.Now().Month())), -1) a.IndexName = strings.Replace(a.IndexName, "%m", fmt.Sprintf("%0.2d", time.Now().Month()), -1)
a.IndexName = strings.Replace(a.IndexName, "%d", strconv.Itoa(time.Now().Day()), -1) a.IndexName = strings.Replace(a.IndexName, "%d", fmt.Sprintf("%0.2d", time.Now().Day()), -1)
a.IndexName = strings.Replace(a.IndexName, "%H", strconv.Itoa(time.Now().Hour()), -1) a.IndexName = strings.Replace(a.IndexName, "%H", fmt.Sprintf("%0.2d", time.Now().Hour()), -1)
} }
exists, errExists := a.Client.IndexExists(a.IndexName).Do() exists, errExists := a.Client.IndexExists(a.IndexName).Do()

View File

@ -18,7 +18,7 @@ func TestConnectAndWrite(t *testing.T) {
e := &Elasticsearch{ e := &Elasticsearch{
ServerHost: serverhost, ServerHost: serverhost,
IndexName: "littletest", IndexName: "littletest-%Y%m%d",
NumberOfShards: 1, NumberOfShards: 1,
NumberOfReplicas: 0, NumberOfReplicas: 0,
} }