From 14766682702c07f26c451f1b6bf2e3eb8a006a10 Mon Sep 17 00:00:00 2001 From: 龙赣华 <slongertian@gmail.com> Date: 星期三, 22 五月 2019 11:51:56 +0800 Subject: [PATCH] modify filemaxage and filerotation between two file --- esutil/EsClient.go | 28 +++++++++++++++++++--------- 1 files changed, 19 insertions(+), 9 deletions(-) diff --git a/esutil/EsClient.go b/esutil/EsClient.go index 57fdb75..fdf50d6 100644 --- a/esutil/EsClient.go +++ b/esutil/EsClient.go @@ -2,6 +2,7 @@ import ( "encoding/json" + "errors" "fmt" "io" "io/ioutil" @@ -14,11 +15,10 @@ ) func GetEsDataReq(url string, parama string, isSource bool) (error, map[string]interface{}) { - log.Log.Infoln("es 鏌ヨ璇锋眰璺緞" + url) // 閰嶇疆淇℃伅 鑾峰彇 + //log.Log.Infoln("es 鏌ヨ璇锋眰璺緞" + url) // 閰嶇疆淇℃伅 鑾峰彇 req, err := http.NewRequest("POST", url, strings.NewReader(parama)) if err != nil { - log.Log.Errorln("build request error! ") return err, nil } @@ -42,24 +42,34 @@ dec := json.NewDecoder(strings.NewReader(jsonStr)) if err := dec.Decode(&dat); err == io.EOF { - log.Log.Infoln(err.Error()) return err, nil } else if err != nil { - log.Log.Errorln(err.Error()) return err, nil } // 鏄惁闇�瑕� 瑙f瀽 es 杩斿洖鐨� source if isSource { - dat = dat["hits"].(map[string]interface{}) + dat, ok := dat["hits"].(map[string]interface{}) + if !ok { + return errors.New("data is not type of map[string]interface{}"), nil + } + var data = make(map[string]interface{}, 2) data["total"] = dat["total"] sources := []interface{}{} for _, value := range dat["hits"].([]interface{}) { - source := value.(map[string]interface{})["_source"].(map[string]interface{}) + source, ok := value.(map[string]interface{})["_source"].(map[string]interface{}) + if !ok { + return errors.New("value is not type of map[string]interface{}"), nil + } + source["id"] = value.(map[string]interface{})["_id"] sdkType := source["sdkType"] if sdkType != nil { - sdk, _ := strconv.Atoi(sdkType.(string)) + sdk, err := strconv.Atoi(sdkType.(string)) + if err != nil { + return err, nil + } + source["sdkType"] = sdkTypeToValue(sdk) } sources = append(sources, source) @@ -85,8 +95,8 @@ seccond := strconv.Itoa(sec) prama := "{\"query\":{\"bool\":{\"filter\":[{\"term\":{\"personIsHub\":\"1\"}},{\"range\":{\"picDate\":{\"gte\":\"now+8h-" + seccond + "s\",\"lt\":\"now+8h\"}}}]}},\"size\":\"1000\",\"sort\":[{\"picDate\":{\"order\":\"desc\"}}]," + - "\"_source\":[\"BaseName\",\"Gender\",\"Race\",\"content\",\"idcard\",\"picAddress\",\"picDate\",\"sdkType\",\"Age\",\"personId\",\"personIsHub\",\"personPicUrl\",\"picLocalUrl\",\"picSmUrl\",\"videoIp\",\"videoNum\",\"videoReqNum\",\"ageDescription\",\"likePer\",\"picMaxUrl\"]" + "}" - + "\"_source\":[\"baseInfo\",\"gender\",\"indeviceName\",\"sdkType\",\"ageDescription\",\"content\",\"ID\",\"picAddress\",\"picMaxUrl\",\"picDate\",\"race\",\"videoNum\",\"picSmUrl\",\"taskName\",\"personIsHub\",\"IDCard\",\"videoIp\",\"videoReqNum\"]" + + "}" err, tokenRes := GetEsDataReq(url, prama, true) if err != nil { log.Log.Errorln(err) -- Gitblit v1.8.0