From 86655db5ef2cca9d7cf4eedae879c3a7c4464b9f Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期六, 26 十月 2019 16:10:08 +0800
Subject: [PATCH] func GetAllLocalVideopersonsId get all when analyServerId is null

---
 EsApi.go |   78 +++++++++++++++++++++++++++++++++++++--
 1 files changed, 74 insertions(+), 4 deletions(-)

diff --git a/EsApi.go b/EsApi.go
index 150aa50..391f9e6 100644
--- a/EsApi.go
+++ b/EsApi.go
@@ -327,12 +327,12 @@
 
 	//浣跨敤es搴曞眰鏈哄埗澶勭悊鍒嗛〉
 
+	analyServerFilterStr := ""
 	analyServerId := compareArgs.AnalyServerId
-	if analyServerId == "" {
-		fmt.Println("no analyServerId")
-		return
+	if analyServerId != "" {
+		analyServerFilterStr = "{\"term\":{\"analyServerId\":\"" + analyServerId + "\"}},"
 	}
-	analyServerFilterStr := "{\"term\":{\"analyServerId\":\"" + analyServerId + "\"}},"
+
 
 	//棣栨璇锋眰澶�
 	url := "http://" + serverIp + ":" + serverPort +
@@ -688,3 +688,73 @@
 	//fmt.Println("tmpSource",sources)
 	return sources,nil
 }
+
+//鑱氬悎浠诲姟鍒楄〃锛宼askId+taskName
+func AggregateTaskList(serverIp string, serverPort string, indexName string) (sources []map[string]interface{},err error){
+	url := "http://" + serverIp + ":" + serverPort +
+		"/"+indexName+"/_search"
+	DSLJson := `{
+    "size": 0,
+    "aggs": {
+        "task_status": {
+            "composite": {
+                "sources": [
+                    {
+                        "taskId": {
+                            "terms": {
+                                "field": "taskId"
+                            }
+                        }
+                    },
+                    {
+                        "taskName": {
+                            "terms": {
+                                "field": "taskName.raw"
+                            }
+                        }
+                    }
+                ],
+                "size":"1000"
+            }
+        }
+    }
+}`
+	buf, err := EsReq("POST",url,[]byte(DSLJson))
+	if err != nil {
+		return nil, err
+	}
+	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{}")
+	}
+	middle, ok := out["aggregations"].(map[string]interface{})
+	if !ok {
+		return nil, errors.New("first hits change error!")
+	}
+	task_status, ok := middle["task_status"].(map[string]interface{})
+	if !ok {
+		return nil, errors.New("first hits change error!")
+	}
+
+	for _, in := range task_status["buckets"].([]interface{}){
+		var source = make(map[string]interface{},0)
+		tmpbuf, ok := in.(map[string]interface{})
+		if !ok {
+			fmt.Println("change to source error!")
+			continue
+		}
+		task := tmpbuf["key"].(map[string]interface{})
+		count := int(tmpbuf["doc_count"].(float64))
+		taskName := task["taskName"].(string)
+		taskId := task["taskId"].(string)
+		source["taskName"] = taskName
+		source["taskId"] = taskId
+		source["count"] = count
+		sources = append(sources, source)
+	}
+	//fmt.Println("tmpSource",sources)
+	return sources,nil
+
+}

--
Gitblit v1.8.0