@@ -119,30 +119,6 @@ func (h *APIHandler) getIndexMetrics(ctx context.Context, req *http.Request, clu
119119 }
120120
121121 query := map [string ]interface {}{}
122- query ["query" ]= util.MapStr {
123- "bool" : util.MapStr {
124- "must" : must ,
125- "must_not" : []util.MapStr {
126- {
127- "term" : util.MapStr {
128- "metadata.labels.index_name" : util.MapStr {
129- "value" : "_all" ,
130- },
131- },
132- },
133- },
134- "filter" : []util.MapStr {
135- {
136- "range" : util.MapStr {
137- "timestamp" : util.MapStr {
138- "gte" : min ,
139- "lte" : max ,
140- },
141- },
142- },
143- },
144- },
145- }
146122 indexMetricItems := []GroupMetricItem {}
147123 switch metricKey {
148124 case v1 .IndexStorageMetricKey :
@@ -617,7 +593,6 @@ func (h *APIHandler) getIndexMetrics(ctx context.Context, req *http.Request, clu
617593
618594 aggs := map [string ]interface {}{}
619595 sumAggs := util.MapStr {}
620- var filterSubAggs = util.MapStr {}
621596
622597 for _ ,metricItem := range indexMetricItems {
623598 leafAgg := util.MapStr {
@@ -626,22 +601,7 @@ func (h *APIHandler) getIndexMetrics(ctx context.Context, req *http.Request, clu
626601 },
627602 }
628603 var sumBucketPath = "term_shard>" + metricItem .ID
629- if metricItem .MetricItem .OnlyPrimary {
630- filterSubAggs [metricItem .ID ] = leafAgg
631- aggs ["filter_pri" ]= util.MapStr {
632- "filter" : util.MapStr {
633- "term" : util.MapStr {
634- "payload.elasticsearch.shard_stats.routing.primary" : util.MapStr {
635- "value" : true ,
636- },
637- },
638- },
639- "aggs" : filterSubAggs ,
640- }
641- sumBucketPath = "term_shard>filter_pri>" + metricItem .ID
642- }else {
643- aggs [metricItem .ID ]= leafAgg
644- }
604+ aggs [metricItem .ID ]= leafAgg
645605
646606 sumAggs [metricItem .ID ] = util.MapStr {
647607 "sum_bucket" : util.MapStr {
@@ -655,11 +615,7 @@ func (h *APIHandler) getIndexMetrics(ctx context.Context, req *http.Request, clu
655615 "field" : metricItem .Field2 ,
656616 },
657617 }
658- if metricItem .MetricItem .OnlyPrimary {
659- filterSubAggs [metricItem .ID + "_field2" ] = leafAgg2
660- }else {
661- aggs [metricItem .ID + "_field2" ] = leafAgg2
662- }
618+ aggs [metricItem .ID + "_field2" ] = leafAgg2
663619 sumAggs [metricItem .ID + "_field2" ] = util.MapStr {
664620 "sum_bucket" : util.MapStr {
665621 "buckets_path" : sumBucketPath + "_field2" ,
@@ -695,6 +651,40 @@ func (h *APIHandler) getIndexMetrics(ctx context.Context, req *http.Request, clu
695651 panic (err )
696652 }
697653
654+ //we can do this because we are querying one metric once time
655+ if indexMetricItems [0 ].MetricItem .OnlyPrimary {
656+ must = append (must , util.MapStr {
657+ "term" : util.MapStr {
658+ "payload.elasticsearch.shard_stats.routing.primary" : util.MapStr {
659+ "value" : true ,
660+ },
661+ },
662+ })
663+ }
664+ query ["query" ]= util.MapStr {
665+ "bool" : util.MapStr {
666+ "must" : must ,
667+ "must_not" : []util.MapStr {
668+ {
669+ "term" : util.MapStr {
670+ "metadata.labels.index_name" : util.MapStr {
671+ "value" : "_all" ,
672+ },
673+ },
674+ },
675+ },
676+ "filter" : []util.MapStr {
677+ {
678+ "range" : util.MapStr {
679+ "timestamp" : util.MapStr {
680+ "gte" : min ,
681+ "lte" : max ,
682+ },
683+ },
684+ },
685+ },
686+ },
687+ }
698688 query ["size" ]= 0
699689 query ["aggs" ]= util.MapStr {
700690 "group_by_level" : util.MapStr {
0 commit comments