尝试给上报到elasticsearch的文档加_id

This commit is contained in:
zhangkun 2024-12-03 23:51:14 +08:00
parent b76a23b9d1
commit 0bec1b219e
3 changed files with 5 additions and 4 deletions

View File

@ -186,9 +186,6 @@ func hashString(input string) string {
func (cl *Candle) ToStruct(core *Core) error {
// cl.Timestamp
str := cl.InstId + "." + cl.Period + "." + cl.Data[0].(string)
cl.Id = hashString(str)
// 将字符串转换为 int64 类型的时间戳
ts, err := strconv.ParseInt(cl.Data[0].(string), 10, 64)
if err != nil {
@ -287,11 +284,14 @@ func (core *Core) SaveUniKey(period string, keyName string, extt time.Duration,
fmt.Println("refName exist: ", refName)
return
}
did := cl.InstId + cl.Period + cl.Data[0].(string)
cl.ToStruct(core)
cd, _ := json.Marshal(cl)
wg := WriteLog{
Content: cd,
Tag: "sardine.log.candle." + cl.Period,
Id: hashString(did),
}
err = wg.Process(core)
if err != nil {

View File

@ -12,6 +12,7 @@ import (
type WriteLog struct {
Content []byte
Tag string
Id string
}
func (wg *WriteLog) Process(cr *Core) error {
@ -19,7 +20,7 @@ func (wg *WriteLog) Process(cr *Core) error {
reqBody := bytes.NewBuffer(wg.Content)
cr.Env = os.Getenv("GO_ENV")
cr.FluentBitUrl = os.Getenv("TEXUS_FluentBitUrl")
fullUrl := "http://" + cr.FluentBitUrl + "/" + wg.Tag
fullUrl := "http://" + cr.FluentBitUrl + "/" + wg.Tag + "/_doc/" + wg.Id
res, err := http.Post(fullUrl, "application/json", reqBody)
fmt.Println("requested, response:", fullUrl, string(wg.Content), res)

BIN
tunas

Binary file not shown.