filter dashbard by cluster id
This commit is contained in:
parent
1bce8cc200
commit
7af5c22a1b
|
@ -5,7 +5,6 @@
|
||||||
package insight
|
package insight
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
httprouter "infini.sh/framework/core/api/router"
|
httprouter "infini.sh/framework/core/api/router"
|
||||||
"infini.sh/framework/core/insight"
|
"infini.sh/framework/core/insight"
|
||||||
"infini.sh/framework/core/orm"
|
"infini.sh/framework/core/orm"
|
||||||
|
@ -13,7 +12,6 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
log "src/github.com/cihub/seelog"
|
log "src/github.com/cihub/seelog"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *InsightAPI) createDashboard(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (h *InsightAPI) createDashboard(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
|
@ -146,17 +144,12 @@ func (h *InsightAPI) deleteDashboard(w http.ResponseWriter, req *http.Request, p
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *InsightAPI) searchDashboard(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (h *InsightAPI) searchDashboard(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
keyword = h.GetParameterOrDefault(req, "keyword", "")
|
keyword = h.GetParameterOrDefault(req, "keyword", "")
|
||||||
queryDSL = `{"query":{"bool":{"must":[%s]}}, "size": %d, "from": %d}`
|
|
||||||
strSize = h.GetParameterOrDefault(req, "size", "20")
|
strSize = h.GetParameterOrDefault(req, "size", "20")
|
||||||
strFrom = h.GetParameterOrDefault(req, "from", "0")
|
strFrom = h.GetParameterOrDefault(req, "from", "0")
|
||||||
mustBuilder = &strings.Builder{}
|
clusterID = h.GetParameter(req, "cluster_id")
|
||||||
)
|
)
|
||||||
if keyword != "" {
|
|
||||||
mustBuilder.WriteString(fmt.Sprintf(`{"query_string":{"default_field":"*","query": "%s"}}`, keyword))
|
|
||||||
}
|
|
||||||
size, _ := strconv.Atoi(strSize)
|
size, _ := strconv.Atoi(strSize)
|
||||||
if size <= 0 {
|
if size <= 0 {
|
||||||
size = 20
|
size = 20
|
||||||
|
@ -166,9 +159,38 @@ func (h *InsightAPI) searchDashboard(w http.ResponseWriter, req *http.Request, p
|
||||||
from = 0
|
from = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
q := orm.Query{}
|
must := []util.MapStr{}
|
||||||
queryDSL = fmt.Sprintf(queryDSL, mustBuilder.String(), size, from)
|
if keyword != "" {
|
||||||
q.RawQuery = []byte(queryDSL)
|
must = append(must, util.MapStr{
|
||||||
|
"query_string": util.MapStr{
|
||||||
|
"default_field":"*",
|
||||||
|
"query": keyword,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if clusterID != "" {
|
||||||
|
must = append(must, util.MapStr{
|
||||||
|
"term": util.MapStr{
|
||||||
|
"cluster_id": util.MapStr{
|
||||||
|
"value": clusterID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
queryDSL := util.MapStr{
|
||||||
|
"size": size,
|
||||||
|
"from": from,
|
||||||
|
"query": util.MapStr{
|
||||||
|
"bool": util.MapStr{
|
||||||
|
"must": must,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
q := orm.Query{
|
||||||
|
RawQuery: util.MustToJSONBytes(queryDSL),
|
||||||
|
}
|
||||||
|
|
||||||
err, res := orm.Search(&insight.Dashboard{}, &q)
|
err, res := orm.Search(&insight.Dashboard{}, &q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue