| | |
| | | package esutil |
| | | |
| | | import ( |
| | | "bytes" |
| | | "encoding/json" |
| | | "errors" |
| | | "fmt" |
| | |
| | | |
| | | log "andriodServer/log" |
| | | ) |
| | | |
| | | func EsReq(method string, url string, parama []byte) (buf []byte, err error) { |
| | | //defer elapsed("page")() |
| | | timeout := time.Duration(100 * time.Second) |
| | | client := http.Client{ |
| | | Timeout: timeout, |
| | | } |
| | | request, err := http.NewRequest(method, url, bytes.NewBuffer(parama)) |
| | | request.Header.Set("Content-type", "application/json") |
| | | |
| | | if err != nil { |
| | | fmt.Println("build request fail !") |
| | | return nil, err |
| | | } |
| | | |
| | | resp, err := client.Do(request) |
| | | if err != nil { |
| | | fmt.Println("request error: ", err) |
| | | return nil, err |
| | | } |
| | | |
| | | defer resp.Body.Close() |
| | | body, err := ioutil.ReadAll(resp.Body) |
| | | if err != nil { |
| | | fmt.Println(err) |
| | | return nil, err |
| | | } |
| | | return body, nil |
| | | } |
| | | |
| | | func GetEsDataReq(url string, param string, isSource bool) (error, map[string]interface{}) { |
| | | req, err := http.NewRequest("POST", url, strings.NewReader(param)) |
| | |
| | | } else { |
| | | d["picMaxUrl"] = "" |
| | | } |
| | | d["picAddress"] = source["cameraAddr"] |
| | | |
| | | tB, err := json.Marshal(source["targetInfo"]) |
| | | if err != nil { |
| | |
| | | } |
| | | d["sdkType"] = "人脸" |
| | | } else { |
| | | d["sdkType"] = source["sdkName"] |
| | | d["sdkType"] = source["taskName"] |
| | | d["picSmUrl"] = d["picMaxUrl"] |
| | | } |
| | | } else { |
| | |
| | | filterStr = strings.Join(filterArr, ",") |
| | | } |
| | | param := "{\"query\":{\"bool\":{\"filter\":["+filterStr+"]}},\"size\":\""+sizeStr+"\",\"sort\":[{\"picDate\":{\"order\":\"desc\"}}]," + |
| | | "\"_source\":{\"includes\":[\"baseInfo\",\"targetInfo\",\"content\",\"id\",\"picMaxUrl\",\"picDate\",\"showLabels\",\"taskName\",\"sdkName\"],\"excludes\":[\"*.feature\",\"*.attachTarget\",\"*.targetLocation\",\"alarmRules\"]}" + |
| | | "\"_source\":{\"includes\":[\"cameraAddr\",\"baseInfo\",\"targetInfo\",\"content\",\"id\",\"picMaxUrl\",\"picDate\",\"showLabels\",\"taskName\",\"sdkName\",\"videoUrl\"],\"excludes\":[\"*.feature\",\"*.attachTarget\",\"*.targetLocation\",\"alarmRules\"]}" + |
| | | "}" |
| | | err, tokenRes := GetEsDataReq(url, param, true) |
| | | |