蛋蛋星球-客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3 viikkoa sitten
123456789101112131415161718192021222324252627282930313233
  1. package hdl
  2. import (
  3. "applet/app/utils"
  4. "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es"
  5. "context"
  6. "github.com/olivere/elastic/v7"
  7. )
  8. func EsSelect(ctx context.Context, index string, query elastic.Query, trackTotalHits bool, arg map[string]string) (*elastic.SearchResult, error) {
  9. if arg["size"] == "" {
  10. arg["size"] = arg["limit"]
  11. }
  12. result, err := es.EsClient.Search().
  13. Index(index).
  14. TrackTotalHits(trackTotalHits).
  15. Query(query). // 设置查询条件
  16. Size(utils.StrToInt(arg["size"])). // 设置分页参数 - 每页大小,设置为0,代表不返回搜索结果,仅返回聚合分析结果
  17. From((utils.StrToInt(arg["p"]) - 1) * utils.StrToInt(arg["size"])).
  18. Pretty(true). // 返回可读的json格式
  19. Do(ctx)
  20. return result, err
  21. }
  22. func EsSelectOne(ctx context.Context, index string, query elastic.Query, trackTotalHits bool) (*elastic.SearchResult, error) {
  23. result, err := es.EsClient.Search().
  24. Index(index).
  25. TrackTotalHits(trackTotalHits).
  26. Query(query). // 设置查询条件
  27. Size(1). // 设置分页参数 - 每页大小,设置为0,代表不返回搜索结果,仅返回聚合分析结果
  28. Pretty(true). // 返回可读的json格式
  29. Do(ctx)
  30. return result, err
  31. }