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"`
|
BucketSize string `json:"bucket_size,omitempty"`
|
||||||
Filter interface{} `json:"filter,omitempty"`
|
Filter interface{} `json:"filter,omitempty"`
|
||||||
Groups []MetricGroupItem `json:"groups,omitempty"` //bucket group
|
Groups []MetricGroupItem `json:"groups,omitempty"` //bucket group
|
||||||
|
Sort []GroupSort `json:"sort,omitempty"`
|
||||||
ClusterId string `json:"cluster_id,omitempty"`
|
ClusterId string `json:"cluster_id,omitempty"`
|
||||||
Formula string `json:"formula,omitempty"`
|
Formula string `json:"formula,omitempty"`
|
||||||
Items []MetricItem `json:"items"`
|
Items []MetricItem `json:"items"`
|
||||||
|
@ -25,6 +26,11 @@ type Metric struct {
|
||||||
BucketLabel *BucketLabel `json:"bucket_label,omitempty"`
|
BucketLabel *BucketLabel `json:"bucket_label,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GroupSort struct {
|
||||||
|
Key string `json:"key"`
|
||||||
|
Direction string `json:"direction"`
|
||||||
|
}
|
||||||
|
|
||||||
type MetricGroupItem struct {
|
type MetricGroupItem struct {
|
||||||
Field string `json:"field"`
|
Field string `json:"field"`
|
||||||
Limit int `json:"limit"`
|
Limit int `json:"limit"`
|
||||||
|
|
|
@ -125,11 +125,19 @@ func GenerateQuery(metric *insight.Metric) (interface{}, error) {
|
||||||
if limit <= 0 {
|
if limit <= 0 {
|
||||||
limit = 10
|
limit = 10
|
||||||
}
|
}
|
||||||
groupAgg := util.MapStr{
|
termsCfg := util.MapStr{
|
||||||
"terms": util.MapStr{
|
|
||||||
"field": groups[i].Field,
|
"field": groups[i].Field,
|
||||||
"size": limit,
|
"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()
|
groupID := util.GetUUID()
|
||||||
if lastGroupAgg != nil {
|
if lastGroupAgg != nil {
|
||||||
|
|
Loading…
Reference in New Issue