topk
Input Stack:
|
⇨ | Output Stack:
|
Select the top K time series based on a summary statistic. This operation keeps only the K time series with the largest values for the specified statistic, effectively filtering out all but the highest-performing series according to the chosen criteria.
Parameters¶
- expr: The grouped time series expression to select from
- stat: The summary statistic to rank by (
max
,min
,avg
,count
,total
,last
) - k: Number of highest-ranking series to keep (positive integer)
Behavior¶
- Statistical evaluation: Computes the specified statistic for each time series over the query window
- Ranking: Sorts all series by the statistic values in descending order (largest first)
- Selection: Keeps only the first K series (those with the largest statistic values)
- Output: Returns the selected time series with their original data, not the statistic values
Examples¶
Selecting the 2 clusters with the highest maximum values:
Before | After |
name,sps,:eq, (,nf.cluster,),:by | name,sps,:eq, (,nf.cluster,),:by, max,2,:topk |
Others Aggregation¶
For including aggregate summaries of the excluded series, use the :topk-others-*
operators:
- :topk-others-avg - Include average of excluded series
- :topk-others-max - Include maximum of excluded series
- :topk-others-min - Include minimum of excluded series
- :topk-others-sum - Include sum of excluded series
Related Operations¶
- :bottomk - Select bottom K time series (smallest values)
- :limit - Limit results after sorting (different ranking criteria)
- :sort - Sort time series by statistics
- :filter - Filter based on statistical criteria
- :stat - Compute statistics used for ranking
Since: 1.7