diff --git a/plugins/outputs/elasticsearch/elasticsearch.go b/plugins/outputs/elasticsearch/elasticsearch.go index d6e5ac079..4b8b618cb 100644 --- a/plugins/outputs/elasticsearch/elasticsearch.go +++ b/plugins/outputs/elasticsearch/elasticsearch.go @@ -77,9 +77,9 @@ func (a *Elasticsearch) Connect() error { year := strconv.Itoa(time.Now().Year()) 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, "%m", strconv.Itoa(int(time.Now().Month())), -1) - a.IndexName = strings.Replace(a.IndexName, "%d", strconv.Itoa(time.Now().Day()), -1) - a.IndexName = strings.Replace(a.IndexName, "%H", strconv.Itoa(time.Now().Hour()), -1) + a.IndexName = strings.Replace(a.IndexName, "%m", fmt.Sprintf("%0.2d", time.Now().Month()), -1) + a.IndexName = strings.Replace(a.IndexName, "%d", fmt.Sprintf("%0.2d", time.Now().Day()), -1) + a.IndexName = strings.Replace(a.IndexName, "%H", fmt.Sprintf("%0.2d", time.Now().Hour()), -1) } exists, errExists := a.Client.IndexExists(a.IndexName).Do() diff --git a/plugins/outputs/elasticsearch/elasticsearch_test.go b/plugins/outputs/elasticsearch/elasticsearch_test.go index f55c4c07a..12f8424c4 100644 --- a/plugins/outputs/elasticsearch/elasticsearch_test.go +++ b/plugins/outputs/elasticsearch/elasticsearch_test.go @@ -18,7 +18,7 @@ func TestConnectAndWrite(t *testing.T) { e := &Elasticsearch{ ServerHost: serverhost, - IndexName: "littletest", + IndexName: "littletest-%Y%m%d", NumberOfShards: 1, NumberOfReplicas: 0, }