#docs #tql

TopNMetricSpec

Specifies how topN values should be sorted.

Numeric TopNMetricSpec

Indicates the metric to sort topN results by, e.g. “count” in this example:

"metric": {
  "type": "numeric",
  "metric": "count"
}

Dimension TopNMetricSpec

This metric specification sorts TopN results by dimension value.

"metric": {
  "type": "dimension",
  "ordering": "lexicographic",
  "previousStop": "<previousStop_value>"
}

Possible sorting orders are:

OrderingDescription
lexicographicSorts values by converting Strings to their UTF-8 byte array representations and comparing lexicographically, byte-by-byte.
alphanumericSuitable for strings with both numeric and non-numeric content. file12 sorts after file2.
numericSorts values as numbers.
strlenSorts values by their string lengths. When there is a tie, this comparator falls back to using the String compareTo method.
versionSorts values as versions. 10.0 sorts after 9.0, 1.0.0-SNAPSHOT sorts after 1.0.0.

previousStop is an optional string and the starting point of the sort. For example, if a previousStop value is b, all values before b are discarded. This field can be used to paginate through all the dimension values.

Inverted TopNMetricSpec

Inverts the order of the delegate metric spec and sorts dimension values in inverted order. It can be used to sort the values in ascending order.

"metric": {
    "type": "inverted",
    "metric": <delegate_top_n_metric_spec>
}