func NewClient(url string, maxRetries int, esIndexPerfix, esType string, timeout time.Duration) *Client {
	client, err := elastic.NewClient(
		elastic.SetURL(url),
		elastic.SetMaxRetries(maxRetries),
	)
	if err != nil {
		log.Fatal(err)
	}
	esIndex := generateEsIndex(esIndexPerfix)
	exists, err := client.IndexExists(esIndex).Do()
	if err != nil {
		log.Errorf("index %v is not found in Elastic.", esIndex)
	}
	if !exists {
		createIndex, err := client.CreateIndex(esIndex).Do()
		if err != nil {
			log.Fatalf("failed to create index %v, err: %v", esIndex, err)
		}
		if !createIndex.Acknowledged {
			log.Fatalf("elasticsearch no acknowledged.")
		}
	}
	return &Client{
		client:  client,
		esIndex: esIndex,
		esType:  esType,
		timeout: timeout,
		ignoredSamples: prometheus.NewCounter(
			prometheus.CounterOpts{
				Name: "prometheus_elasticsearch_ignored_samples_total",
				Help: "The total number of samples not sent to Elasticsearch due to unsupported float values (Inf, -Inf, NaN).",
			},
		),
	}
}
NewClient return a Client which contains an elasticsearch client.
Now, it generates the real esIndex formatted with `<esIndexPerfix>-YYYY-mm-dd`.
package elasticsearch
import (
	"encoding/json"
	"math"
	"time"
	"github.com/prometheus/client_golang/prometheus"
	"github.com/prometheus/common/log"
	"github.com/prometheus/common/model"
	elastic "gopkg.in/olivere/elastic.v3"
)
type Client struct {
	client         *elastic.Client
	esIndex        string
	esType         string
	timeout        time.Duration
	ignoredSamples prometheus.Counter
}
func fieldsFromMetric(m model.Metric) map[string]interface{} {
	fields := make(map[string]interface{}, len(m))
	for l, v := range m {
		fields[string(l)] = string(v)
	}
	return fields
}
func generateEsIndex(esIndexPerfix string) string {
	var separator = "-"
	dateSuffix := time.Now().Format("2006-01-02")
	return esIndexPerfix + separator + dateSuffix
}