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 }