bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/cmd/bosun/sched/esquery7.go (about) 1 package sched 2 3 import ( 4 "encoding/json" 5 6 "bosun.org/cmd/bosun/expr" 7 elastic "github.com/olivere/elastic/v7" 8 ) 9 10 func (c *Context) esQuery7(indexRoot expr.ESIndexer, filter expr.ESQuery, sduration, eduration string, size int) interface{} { 11 newFilter := expr.ScopeES7(c.Group(), filter.Query(expr.ESV7).(elastic.Query)) 12 req, err := expr.ESBaseQuery7(c.runHistory.Start, indexRoot, newFilter, sduration, eduration, size, c.ElasticHost) 13 if err != nil { 14 c.addError(err) 15 return nil 16 } 17 results, err := c.runHistory.Backends.ElasticHosts.Query7(req) 18 if err != nil { 19 c.addError(err) 20 return nil 21 } 22 r := make([]interface{}, len(results.Hits.Hits)) 23 for i, h := range results.Hits.Hits { 24 var err error 25 err = json.Unmarshal(h.Source, &r[i]) 26 if err != nil { 27 c.addError(err) 28 return nil 29 } 30 } 31 return r 32 } 33 34 func (c *Context) esQueryAll7(indexRoot expr.ESIndexer, filter expr.ESQuery, sduration, eduration string, size int) interface{} { 35 req, err := expr.ESBaseQuery7(c.runHistory.Start, indexRoot, filter.Query(expr.ESV7).(elastic.Query), sduration, eduration, size, c.ElasticHost) 36 if err != nil { 37 c.addError(err) 38 return nil 39 } 40 results, err := c.runHistory.Backends.ElasticHosts.Query7(req) 41 if err != nil { 42 c.addError(err) 43 return nil 44 } 45 r := make([]interface{}, len(results.Hits.Hits)) 46 for i, h := range results.Hits.Hits { 47 var err error 48 err = json.Unmarshal(h.Source, &r[i]) 49 if err != nil { 50 c.addError(err) 51 return nil 52 } 53 } 54 return r 55 }