dm_history.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/app/service/main/search/model"
  6. elastic "gopkg.in/olivere/elastic.v5"
  7. )
  8. func (d *Dao) DmHistory(c context.Context, p *model.DmHistoryParams) (res *model.SearchResult, err error) {
  9. var (
  10. query = elastic.NewBoolQuery()
  11. indexName = fmt.Sprintf("dm_search_%03d", p.Oid%1000)
  12. )
  13. if p.Bsp.KW != "" {
  14. query = query.Must(elastic.NewMultiMatchQuery(p.Bsp.KW, p.Bsp.KwFields...).Type("best_fields").TieBreaker(0.6))
  15. }
  16. if p.Oid != -1 {
  17. query = query.Filter(elastic.NewTermQuery("oidstr", p.Oid))
  18. }
  19. if len(p.States) > 0 {
  20. interfaceSlice := make([]interface{}, len(p.States))
  21. for k, m := range p.States {
  22. interfaceSlice[k] = m
  23. }
  24. query = query.Filter(elastic.NewTermsQuery("state", interfaceSlice...))
  25. }
  26. if p.CtimeFrom != "" {
  27. query = query.Filter(elastic.NewRangeQuery("ctime").Gte(p.CtimeFrom))
  28. }
  29. if p.CtimeTo != "" {
  30. query = query.Filter(elastic.NewRangeQuery("ctime").Lte(p.CtimeTo))
  31. }
  32. fmt.Println(indexName)
  33. if res, err = d.searchResult(c, "dmExternal", indexName, query, p.Bsp); err != nil {
  34. PromError(fmt.Sprintf("es:%s ", p.Bsp.AppID), "%v", err)
  35. }
  36. return
  37. }