From 1fd88458565968b93b4460b8a0cd8fc8fef9408d Mon Sep 17 00:00:00 2001
From: Johan Solbakken
+ Use
When all arguments are numeric, the result type is resolved by looking at the argument types.
@@ -345,6 +346,16 @@ Collecting aggregates
select * from purchase where true limit 0 |
all(group(customer) each(output(quantiles([0.5,0.9], price))))
+argmin or argmax to return the value of one field for the document
+ with the smallest or largest value of another, for instance the item of the most expensive purchase per customer:
+select * from purchase where true limit 0 |
+ all(group(customer) each(output(argmax(price, item))))
+
diff --git a/en/reference/querying/grouping-language.html b/en/reference/querying/grouping-language.html
index a006d1e491..346babab39 100644
--- a/en/reference/querying/grouping-language.html
+++ b/en/reference/querying/grouping-language.html
@@ -325,6 +325,7 @@ Aggregators
Aggregators
all( group(city) each(output(quantiles([0.5, 0.9], delivery_days))) )
This computes the median (p50) and 90th percentile (p90) time to delivery in days per city. Note that quantiles are computed using KLL Sketch, so they are approximate.
+Use argmin(key, value) and argmax(key, value) to get the value of one expression
+for the document that has the smallest or largest value of another expression:
+
all( group(artist) each(output(argmin(price, title))) )+This outputs the title of the cheapest track per artist, where
min(price) would only output the price.
+The key must be numeric, while the value can be of any type, including multivalue.
+Documents where the key is not set are skipped, and the output is null if no document in the group has a key.
+If several documents share the smallest or largest key, one of them is selected.
+Both can be used in order, e.g. order(-argmin(price, title)).
+Available since {% include version.html version="8.761.27" %}.
+
Multivalue fields, such as maps and arrays, can be used for grouping.
However, using aggregation functions such as sum() on such fields can give misleading results.
Assume a map from strings to integers (map<string, int>),
@@ -381,6 +392,8 @@