From b7a57cd830201952d76b5df4c7e10097317d4f10 Mon Sep 17 00:00:00 2001 From: sunty <1172534965@qq.com> Date: 星期日, 29 九月 2019 15:25:23 +0800 Subject: [PATCH] fix EsApi --- EsClient.go | 68 ++++++++++++++++++++++++++++++--- 1 files changed, 61 insertions(+), 7 deletions(-) diff --git a/EsClient.go b/EsClient.go index 5a8d88b..9a69741 100644 --- a/EsClient.go +++ b/EsClient.go @@ -7,7 +7,8 @@ "fmt" "io/ioutil" "net/http" - "time" + "strconv" + "time" "basic.com/pubsub/protomsg.git" ) @@ -109,9 +110,11 @@ tmpinfo.BeautyLevel,ok = source["beautyLevel"].(string) Isnil("beautyLevel",ok) if source["picSmUrl"] != nil { + //fmt.Println(source["picSmUrl"]) for _,v := range source["picSmUrl"].([]interface{}) { tmpinfo.PicSmUrl = append(tmpinfo.PicSmUrl, v.(string)) } + fmt.Println(tmpinfo.PicSmUrl) } tmpinfo.VideoUrl,ok = source["videoUrl"].(string) Isnil("videoUrl",ok) @@ -123,21 +126,33 @@ Isnil("analyServerIp",ok) tmpinfo.ClusterId,ok = source["clusterId"].(string) Isnil("clusterId",ok) - tmpinfo.IsAlarm,ok = source["isAlarm"].(string) + + isAlarm,ok := source["isAlarm"].(float64) + fmt.Println(ok) + if ok { + tmpinfo.IsAlarm= strconv.FormatFloat(isAlarm, 'E', -1, 64)//float64 + } Isnil("isAlarm",ok) - tmpinfo.IsAckAlarm,ok = source["isAckAlarm"].(string) - Isnil("isAckAlarm",ok) + + isAckAlarm,ok := source["isAckAlarm"].(float64) + fmt.Println(ok) + if ok { + tmpinfo.IsAckAlarm= strconv.FormatFloat(isAckAlarm, 'E', -1, 64)//float64 + } + Isnil("isAckAlarm",ok) isCollect,ok := source["isCollect"].(float64) if ok { tmpinfo.IsDelete= int32(isCollect) } - Isnil("isDelete", ok) + Isnil("isCollect", ok) + isDelete,ok := source["isDelete"].(float64) if ok { tmpinfo.IsDelete= int32(isDelete) } Isnil("isDelete", ok) + if source["alarmRules"] != nil { fmt.Println(source["alarmRules"]) for _,v := range source["alarmRules"].([]interface{}) { @@ -195,12 +210,12 @@ tmpinfo.BaseInfo = append(tmpinfo.BaseInfo, &bi) } - } //鏍规嵁 tableid 鑾峰彇 tablename //name, _:= Dbtablename(tmpinfo.TableId) //tmpinfo.TableName= name + fmt.Println(tmpinfos) tmpinfos = append(tmpinfos, tmpinfo) } @@ -358,8 +373,47 @@ return sources,nil } +func Sourcelistforscroll(buf []byte)(datasource map[string]interface{}, err error){ + var data = make(map[string]interface{}) + var info interface{} + json.Unmarshal(buf, &info) + out, ok := info.(map[string]interface{}) + if !ok { + return nil, errors.New("http response interface can not change map[string]interface{}") + } + scroll_id, ok := out["_scroll_id"].(string) + if !ok { + return nil, errors.New("first hits change error!") + } + + //fmt.Println("middle: ",scroll_id) + middle, ok := out["hits"].(map[string]interface{}) + //fmt.Println("middle: ",out) + if !ok { + return nil, errors.New("first hits change error!") + } + var sources = make([]map[string]interface{},0) + for _, in := range middle["hits"].([]interface{}){ + tmpbuf, ok := in.(map[string]interface{}) + if !ok { + fmt.Println("change to source error!") + continue + } + source, ok := tmpbuf["_source"].(map[string]interface{}) + if !ok { + fmt.Println("change _source error!") + continue + } + sources = append(sources, source ) + } + + data["sourcelist"] = sources + data["scroll_id"] = scroll_id + return data,nil +} + func EsReq(method string, url string, parama []byte) (buf []byte, err error) { - defer elapsed("page")() + //defer elapsed("page")() timeout := time.Duration(10 * time.Second) client := http.Client{ Timeout: timeout, -- Gitblit v1.8.0