sunty
2020-08-20 9303b69ea569bcb5e581147543a3fd58e90d0d25
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package controllers
 
import (
    "basic.com/valib/logger.git"
    "fmt"
    "strconv"
    "webserver/cache"
 
    "github.com/gin-gonic/gin"
    "webserver/extend/code"
    "webserver/extend/config"
    "webserver/extend/esutil"
    "webserver/extend/util"
)
 
// @Security ApiKeyAuth
// @Summary 任务列表
// @Description 返回任务列表
// @Accept  json
// @Produce json
// @Tags es
// @Success 200 {string} json "{"code":200, msg:"目录结构数据", success:true}"
// @Failure 500 {string} json "{"code":500,  msg:"返回错误信息", success:false}"
// @Router /data/api-v/es/taskList [POST]
func (sc *EsSearchController) PostEsTaskList(c *gin.Context) {
    localConf, err2 := cache.GetServerInfo()
    if err2 !=nil || localConf.AlarmIp == "" || localConf.ServerId == "" {
        logger.Debug("localConfig is wrong!!!")
        util.ResponseFormat(c,code.ComError,"localConf wrong")
        return
    }
    url := "http://" + localConf.AlarmIp + ":" + strconv.Itoa(int(localConf.AlarmPort)) +
        "/" + config.EsInfo.EsIndex.AiOcean.IndexName + "/_search"
 
    prama := "{\"size\":0,\"aggs\":{\"taskId_list\":{\"terms\":{\"field\":\"taskId\"}}}}"
 
    tokenRes := esutil.GetEsDataReq(url, prama, false)
    //var taskId_list map[string]interface{}
    aggs := tokenRes["aggregations"].(map[string]interface{})
    sources := make([]map[string]string, 0)
    if aggs != nil {
        taskId_list, ok := aggs["taskId_list"].(map[string]interface{})["buckets"].([]interface{})
        if !ok {
            fmt.Println("It's not ok for type string")
        }
        for _, value := range taskId_list {
            var key = value.(map[string]interface{})["key"]
            source := make(map[string]string)
            source["title"] = key.(string)
            source["value"] = key.(string)
            source["key"] = key.(string)
            sources = append(sources, source)
            fmt.Println(key)
        }
 
        //m["result"].(map[string]interface{})["A"].([]interface{})[3].(map[string]interface{})["name"]
        fmt.Println(sources)
 
    }
 
    util.ResponseFormat(c, code.Success, sources)
}