|
123456789101112131415161718192021222324252627282930313233 |
- package hdl
-
- import (
- "applet/app/utils"
- "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es"
- "context"
- "github.com/olivere/elastic/v7"
- )
-
- func EsSelect(ctx context.Context, index string, query elastic.Query, trackTotalHits bool, arg map[string]string) (*elastic.SearchResult, error) {
- if arg["size"] == "" {
- arg["size"] = arg["limit"]
- }
- result, err := es.EsClient.Search().
- Index(index).
- TrackTotalHits(trackTotalHits).
- Query(query). // 设置查询条件
- Size(utils.StrToInt(arg["size"])). // 设置分页参数 - 每页大小,设置为0,代表不返回搜索结果,仅返回聚合分析结果
- From((utils.StrToInt(arg["p"]) - 1) * utils.StrToInt(arg["size"])).
- Pretty(true). // 返回可读的json格式
- Do(ctx)
- return result, err
- }
- func EsSelectOne(ctx context.Context, index string, query elastic.Query, trackTotalHits bool) (*elastic.SearchResult, error) {
- result, err := es.EsClient.Search().
- Index(index).
- TrackTotalHits(trackTotalHits).
- Query(query). // 设置查询条件
- Size(1). // 设置分页参数 - 每页大小,设置为0,代表不返回搜索结果,仅返回聚合分析结果
- Pretty(true). // 返回可读的json格式
- Do(ctx)
- return result, err
- }
|