sunty
2024-05-29 f3236c4f149d269d03a6a621f2cd98ea28c2eb39
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
package db
 
import (
    "basic.com/pubsub/esutil.git"
    "ruleModelEngine/config"
    "strconv"
)
 
func QueryByDays(days int) ([]string, error) {
    esURL := "http://" + config.Elastic.Host + ":" + config.Elastic.Port + "/" + config.Elastic.Index + "/_search"
    queryDSL := `{
    "query": {
        "bool": {
            "filter": [
                {
                    "range": {
                        "picDate": {
                            "gte": "now-` + strconv.Itoa(days) + `d/d"
                        }
                    }
                }
            ]
        }
    },
    "size":22139,
    "_source": [
        "id"
    ]
}`
    ids := make([]string, 0)
    buf, err := esutil.EsReq("POST", esURL, []byte(queryDSL))
    if err != nil {
        return nil, err
    }
    source, err := esutil.Sourcelist(buf)
    if err != nil {
        return nil, err
    }
    for _, info := range source {
        ids = append(ids, info["id"].(string))
    }
    return ids, nil
}