package es

import (
	"context"
	"time"
)

var EWriter = &esWriter{}

type esWriter struct {
}

func (e *esWriter) Write(p []byte) (int, error) {
	str := string(p)
	Client.Index().
		Index(getIndexName()).
		Type("_doc").
		BodyJson(str).Do(context.Background())
	return len(p), nil
}

// 当天日期作为索引名
func getIndexName() string {
	return time.Now().Format("2006-01-02")
}
