From e189b1942c8130d473a1a4128c3d9ef5edfaa564 Mon Sep 17 00:00:00 2001 From: sunty <1172534965@qq.com> Date: 星期五, 23 十月 2020 10:58:30 +0800 Subject: [PATCH] fix --- EsApi.go | 100 +++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 86 insertions(+), 14 deletions(-) diff --git a/EsApi.go b/EsApi.go index 2eb29eb..96348c7 100644 --- a/EsApi.go +++ b/EsApi.go @@ -257,20 +257,23 @@ if err != nil { return nil, err } + if len(source) == 0 { + return source, nil + } faceSource := make([]map[string]interface{}, 0) for index, info := range source { if int(info["stayTime"].(float64)) > thresholdStayTime { faceSource = append(faceSource, source[index]) } } + mapsSort := MapsSort{} + mapsSort.Key = "endTime" + mapsSort.MapList = faceSource + sort.Sort(&mapsSort) if len(faceSource) > total { - mapsSort := MapsSort{} - mapsSort.Key = "endTime" - mapsSort.MapList = faceSource - sort.Sort(&mapsSort) return mapsSort.MapList[:total], nil } - return faceSource, nil + return mapsSort.MapList, nil } func GetFaceDataByTimeAndId(startTime string, endTime string, id string, thresholdTime int, thresholdStayTime int, serverIp string, serverPort string, indexName string) (resData []map[string]interface{}, err error) { @@ -355,13 +358,20 @@ if err != nil { return nil, err } + if len(source) == 0 { + return source, nil + } faceSource := make([]map[string]interface{}, 0) for index, info := range source { if int(info["stayTime"].(float64)) > thresholdStayTime { faceSource = append(faceSource, source[index]) } } - return faceSource, nil + mapsSort := MapsSort{} + mapsSort.Key = "startTime" + mapsSort.MapList = faceSource + sort.Sort(&mapsSort) + return mapsSort.MapList, nil } func GetFaceIdDeduplication(startTime string, endTime string, serverIp string, serverPort string, indexName string) (ids []map[string]interface{}, err error) { @@ -434,7 +444,7 @@ if err1 != nil { return nil, err1 } - if len(ids) > 0 { + if len(ids) > 1 { mapsSort := MapsSort{} mapsSort.Key = "lastTime" mapsSort.MapList = ids @@ -1075,7 +1085,7 @@ if category != "all" { filterArr = append(filterArr, ` { "term":{ - "targetInfo.targetType":"`+category+`" + "targetInfo.targetType.raw":"`+category+`" } }`) @@ -1095,7 +1105,7 @@ "sort":[{"picDate":{"order":"desc"}}], "_source": {"includes":[],"excludes":["*.feature"]} }` - logPrint(DSLJson) + //logPrint(DSLJson) buf, err := EsReq("POST", url, []byte(DSLJson)) if err != nil { return aIOceanInfo, err @@ -1185,7 +1195,6 @@ } } }` - //logPrint(DSLJson) buf, err := EsReq("POST", url, []byte(DSLJson)) if err != nil { return total, err @@ -1223,9 +1232,9 @@ } }, "aggs":{ - "sdkName_status":{ + "taskName_status":{ "terms":{ - "field":"sdkName.raw" + "field":"taskName.raw" } } } @@ -1244,11 +1253,11 @@ if !ok { return nil, errors.New("first hits change error!") } - sdkName_status, ok := middle["sdkName_status"].(map[string]interface{}) + sdkName_status, ok := middle["taskName_status"].(map[string]interface{}) if !ok { return nil, errors.New("first hits change error!") } - + //fmt.Println(sdkName_status) for _, in := range sdkName_status["buckets"].([]interface{}) { var source = make(map[string]interface{}, 0) tmpbuf, ok := in.(map[string]interface{}) @@ -1726,3 +1735,66 @@ } return result, nil } + +type ShardInfo struct { + ShardIndex string `json:"shardIndex"` //鍒嗙墖鎵�灞炵储寮曞悕绉� + ShardNum int `json:"shardNum"` //鍒嗙墖鍙� + ShardRole string `json:"shardRole"` //鍒嗙墖瑙掕壊(涓诲垎鐗囷細primary 鍓湰鍒嗙墖锛歳eplica) + ShardState string `json:"shardState"` //鍒嗙墖鐘舵��(鍚敤锛歋TARTED 鏈惎鐢細UNASSIGNED) + ShardDocs int `json:"shardDocs"` //鍒嗙墖宸蹭繚瀛樻枃妗f暟 + ShardStore string `json:"shardStore"` //鍒嗙墖褰撳墠瀛樺偍鏁版嵁澶у皬 + ShardIp string `json:"shardIp"` //鍒嗙墖鎵�鍦ㄨ妭鐐筰p + ShardNode string `json:"shardNode"` //鍒嗙墖鎵�鍦ㄨ妭鐐瑰悕绉� +} + +//鑾峰彇绱㈠紩鍒嗙墖淇℃伅 +func GetShardsByIndex(serverIp string, serverPort string, indexName string) ([]ShardInfo, error) { + url := "http://" + serverIp + ":" + serverPort + "/_cat/shards?v" + buf, err := EsReq("GET", url, []byte("")) + if err != nil { + return nil, err + } + var inf = []ShardInfo{} + res := strings.Split(string(buf), "\n")[1:] + for _, r := range res { + if r != "" { + + inx := strings.Fields(r) + index := inx[0] + shard, _ := strconv.Atoi(inx[1]) + prired := inx[2] + if prired == "r" { + prired = "replica" + } + if prired == "p" { + prired = "primary" + } + state := inx[3] + docs := 0 + store := "" + ip := "" + node := "" + if state == "STARTED" { + docs, _ = strconv.Atoi(inx[4]) + store = inx[5] + ip = inx[6] + node = inx[7] + } + if index == indexName { + inf = append(inf, ShardInfo{ + ShardIndex: index, + ShardNum: shard, + ShardRole: prired, + ShardState: state, + ShardDocs: docs, + ShardStore: store, + ShardIp: ip, + ShardNode: node, + }) + + } + } + + } + return inf, nil +} -- Gitblit v1.8.0