| | |
| | | |
| | | import ( |
| | | "encoding/json" |
| | | "errors" |
| | | "fmt" |
| | | "io" |
| | | "io/ioutil" |
| | |
| | | ) |
| | | |
| | | 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 |
| | | } |
| | | |
| | |
| | | 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 |
| | | } |
| | | // 是否需要 解析 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) |
| | |
| | | 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) |