insight support terms top by sorted sub metric
This commit is contained in:
parent
7336ebc208
commit
cc25b07439
|
@ -16,6 +16,7 @@ type Metric struct {
|
|||
BucketSize string `json:"bucket_size,omitempty"`
|
||||
Filter interface{} `json:"filter,omitempty"`
|
||||
Groups []MetricGroupItem `json:"groups,omitempty"` //bucket group
|
||||
Sort []GroupSort `json:"sort,omitempty"`
|
||||
ClusterId string `json:"cluster_id,omitempty"`
|
||||
Formula string `json:"formula,omitempty"`
|
||||
Items []MetricItem `json:"items"`
|
||||
|
@ -25,6 +26,11 @@ type Metric struct {
|
|||
BucketLabel *BucketLabel `json:"bucket_label,omitempty"`
|
||||
}
|
||||
|
||||
type GroupSort struct {
|
||||
Key string `json:"key"`
|
||||
Direction string `json:"direction"`
|
||||
}
|
||||
|
||||
type MetricGroupItem struct {
|
||||
Field string `json:"field"`
|
||||
Limit int `json:"limit"`
|
||||
|
|
|
@ -125,11 +125,19 @@ func GenerateQuery(metric *insight.Metric) (interface{}, error) {
|
|||
if limit <= 0 {
|
||||
limit = 10
|
||||
}
|
||||
groupAgg := util.MapStr{
|
||||
"terms": util.MapStr{
|
||||
termsCfg := util.MapStr{
|
||||
"field": groups[i].Field,
|
||||
"size": limit,
|
||||
},
|
||||
}
|
||||
if i == grpLength - 1 && len(metric.Sort) > 0 {
|
||||
var termsOrder []interface{}
|
||||
for _, sortItem := range metric.Sort {
|
||||
termsOrder = append(termsOrder, util.MapStr{sortItem.Key: sortItem.Direction})
|
||||
}
|
||||
termsCfg["order"] = termsOrder
|
||||
}
|
||||
groupAgg := util.MapStr{
|
||||
"terms": termsCfg,
|
||||
}
|
||||
groupID := util.GetUUID()
|
||||
if lastGroupAgg != nil {
|
||||
|
|
Loading…
Reference in New Issue