kibana/x-pack/test/alerting_api_integration
Patrick Mueller d5665921c7
resolves https://github.com/elastic/kibana/issues/58905 (#60120)
The current index threshold alert uses a `size` limit on term aggregation, when used, but does not sort the buckets, so it's just using descending count on the grouped buckets as the sort to determine what to return.

The watcher API for the index threshold notes this as "top N of", implying a sort.

This PR applies sorting when the using `groupBy: top`, and the `aggType != count`.  For count, ES is already sorting the way we want.

The sort is calculated as a separate agg beside the date_range aggregation, which is the same metrics agg specified in the query - `aggType(aggField)`.  This field is then referenced in a new `order` property in the terms agg, using 'asc' sorting for `min`, and `desc` sorting for `avg`, `max`, and `sum`.

This doesn't change the shape of the output at all, just changes which term buckets will be returned, if there are more term buckets than requested with the `termSize` parameter.
2020-03-17 00:29:33 -04:00
..
common [Alerting] extend Alert Type with names/descriptions of action variables (#59756) 2020-03-12 23:17:29 -04:00
security_and_spaces [Alerting] extend Alert Type with names/descriptions of action variables (#59756) 2020-03-12 23:17:29 -04:00
spaces_only resolves https://github.com/elastic/kibana/issues/58905 (#60120) 2020-03-17 00:29:33 -04:00