fixed empty groups of number type

This commit is contained in:
liugq 2022-08-10 09:26:38 +08:00
parent 6b57960882
commit 074663f1be
2 changed files with 33 additions and 8 deletions

View File

@ -336,6 +336,9 @@
{"name": "nodes.info", "methods": ["get"], {"name": "nodes.info", "methods": ["get"],
"path": "/_nodes" "path": "/_nodes"
}, },
{"name": "nodes.info", "methods": ["get"],
"path": "/_nodes/:node_id"
},
{"name": "nodes.stats", "methods": ["get"], {"name": "nodes.stats", "methods": ["get"],
"path": "/_nodes/stats" "path": "/_nodes/stats"
}, },

View File

@ -220,6 +220,7 @@ func getMetadataByIndexPattern(clusterID, indexPattern, timeField string, filter
return nil, err return nil, err
} }
for fieldName, count := range counts { for fieldName, count := range counts {
delete(options, "seriesField")
if count <= 1 { if count <= 1 {
continue continue
} }
@ -229,10 +230,10 @@ func getMetadataByIndexPattern(clusterID, indexPattern, timeField string, filter
if timeField == "" { if timeField == "" {
seriesType = "pie" seriesType = "pie"
}else { }else {
if aggField.Type == "string"{ //if aggField.Type == "string"{
seriesType = "column" seriesType = "column"
options["seriesField"] = "group" options["seriesField"] = "group"
} //}
} }
} }
var defaultAggType string var defaultAggType string
@ -240,8 +241,11 @@ func getMetadataByIndexPattern(clusterID, indexPattern, timeField string, filter
aggTypes = []string{"count", "terms"} aggTypes = []string{"count", "terms"}
defaultAggType = "count" defaultAggType = "count"
} else { } else {
aggTypes = []string{"min", "max", "avg", "sum", "medium", "rate"} aggTypes = []string{"min", "max", "avg", "sum", "medium","count", "rate"}
defaultAggType = "avg" defaultAggType = "avg"
if options["seriesField"] == "group" {
defaultAggType = "count"
}
} }
if fieldsFormat != nil { if fieldsFormat != nil {
@ -266,7 +270,7 @@ func getMetadataByIndexPattern(clusterID, indexPattern, timeField string, filter
}, },
AggTypes: aggTypes, AggTypes: aggTypes,
}} }}
if seriesType == "column" { if seriesType == "column" || seriesType == "pie" {
seriesItem.Metric.Groups = []insight.MetricGroupItem{ seriesItem.Metric.Groups = []insight.MetricGroupItem{
{aggField.Name, 10}, {aggField.Name, 10},
} }
@ -294,7 +298,14 @@ func countFieldValue(fields []string, clusterID, indexPattern string, filter int
} }
queryDsl := util.MapStr{ queryDsl := util.MapStr{
"size": 0, "size": 0,
"aggs": aggs, "aggs": util.MapStr{
"sample": util.MapStr{
"sampler": util.MapStr{
"shard_size": 200,
},
"aggs": aggs,
},
} ,
} }
if filter != nil { if filter != nil {
queryDsl["query"] = filter queryDsl["query"] = filter
@ -305,11 +316,22 @@ func countFieldValue(fields []string, clusterID, indexPattern string, filter int
return nil, err return nil, err
} }
fieldsCount := map[string] float64{} fieldsCount := map[string] float64{}
for key, agg := range searchRes.Aggregations { res := map[string]interface{}{}
if count, ok := agg.Value.(float64); ok { util.MustFromJSONBytes(searchRes.RawResult.Body, &res)
fieldsCount[key] = count if aggsM, ok := res["aggregations"].(map[string]interface{}); ok {
if sampleAgg, ok := aggsM["sample"].(map[string]interface{}); ok {
for key, agg := range sampleAgg {
if key == "doc_count"{
continue
}
if mAgg, ok := agg.(map[string]interface{});ok{
fieldsCount[key] = mAgg["value"].(float64)
}
}
} }
} }
return fieldsCount, nil return fieldsCount, nil
} }