尝试给上报到elasticsearch的文档加_id
This commit is contained in:
parent
b76a23b9d1
commit
0bec1b219e
@ -186,9 +186,6 @@ func hashString(input string) string {
|
|||||||
func (cl *Candle) ToStruct(core *Core) error {
|
func (cl *Candle) ToStruct(core *Core) error {
|
||||||
// cl.Timestamp
|
// cl.Timestamp
|
||||||
|
|
||||||
str := cl.InstId + "." + cl.Period + "." + cl.Data[0].(string)
|
|
||||||
cl.Id = hashString(str)
|
|
||||||
|
|
||||||
// 将字符串转换为 int64 类型的时间戳
|
// 将字符串转换为 int64 类型的时间戳
|
||||||
ts, err := strconv.ParseInt(cl.Data[0].(string), 10, 64)
|
ts, err := strconv.ParseInt(cl.Data[0].(string), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -287,11 +284,14 @@ func (core *Core) SaveUniKey(period string, keyName string, extt time.Duration,
|
|||||||
fmt.Println("refName exist: ", refName)
|
fmt.Println("refName exist: ", refName)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
did := cl.InstId + cl.Period + cl.Data[0].(string)
|
||||||
cl.ToStruct(core)
|
cl.ToStruct(core)
|
||||||
cd, _ := json.Marshal(cl)
|
cd, _ := json.Marshal(cl)
|
||||||
wg := WriteLog{
|
wg := WriteLog{
|
||||||
Content: cd,
|
Content: cd,
|
||||||
Tag: "sardine.log.candle." + cl.Period,
|
Tag: "sardine.log.candle." + cl.Period,
|
||||||
|
Id: hashString(did),
|
||||||
}
|
}
|
||||||
err = wg.Process(core)
|
err = wg.Process(core)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
type WriteLog struct {
|
type WriteLog struct {
|
||||||
Content []byte
|
Content []byte
|
||||||
Tag string
|
Tag string
|
||||||
|
Id string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wg *WriteLog) Process(cr *Core) error {
|
func (wg *WriteLog) Process(cr *Core) error {
|
||||||
@ -19,7 +20,7 @@ func (wg *WriteLog) Process(cr *Core) error {
|
|||||||
reqBody := bytes.NewBuffer(wg.Content)
|
reqBody := bytes.NewBuffer(wg.Content)
|
||||||
cr.Env = os.Getenv("GO_ENV")
|
cr.Env = os.Getenv("GO_ENV")
|
||||||
cr.FluentBitUrl = os.Getenv("TEXUS_FluentBitUrl")
|
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)
|
res, err := http.Post(fullUrl, "application/json", reqBody)
|
||||||
|
|
||||||
fmt.Println("requested, response:", fullUrl, string(wg.Content), res)
|
fmt.Println("requested, response:", fullUrl, string(wg.Content), res)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user