<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Metric aggregations on INFINI Pizza</title><link>/docs/references/aggregation/metric/</link><description>Recent content in Metric aggregations on INFINI Pizza</description><generator>Hugo</generator><language>en</language><atom:link href="/docs/references/aggregation/metric/index.xml" rel="self" type="application/rss+xml"/><item><title>Avg aggregation</title><link>/docs/references/aggregation/metric/avg/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/references/aggregation/metric/avg/</guid><description>&lt;h1 id="avg-aggregation">
 Avg aggregation
 &lt;a class="anchor" href="#avg-aggregation">#&lt;/a>
&lt;/h1>
&lt;p>A single-value metrics aggregation that computes the average of numeric values
that are extracted from the aggregated documents.&lt;/p>
&lt;h2 id="examples">
 Examples
 &lt;a class="anchor" href="#examples">#&lt;/a>
&lt;/h2>
&lt;p>Assuming the data consists of documents representing exams grades (between &lt;code>0&lt;/code>
and &lt;code>100&lt;/code>) of students we can average their scores with:&lt;/p>
&lt;div class="pizza-playground" data-dataset="sales" data-dsl="{
 &amp;#34;size&amp;#34;: 0,
 &amp;#34;aggs&amp;#34;: {
 &amp;#34;avg_price&amp;#34;: {
 &amp;#34;avg&amp;#34;: {
 &amp;#34;field&amp;#34;: &amp;#34;price&amp;#34;
 }
 }
 }
}">
 &lt;noscript>JavaScript is disabled — use the curl form of this example instead.&lt;/noscript>
&lt;/div>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-sh" data-lang="sh">&lt;span class="line">&lt;span class="cl">POST /exams/_search
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;aggs&amp;#34;&lt;/span>: &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;avg_grade&amp;#34;&lt;/span>: &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;avg&amp;#34;&lt;/span>: &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;field&amp;#34;&lt;/span>: &lt;span class="s2">&amp;#34;grade&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>The above aggregation computes the average grade over all documents. The
aggregation type is &lt;code>avg&lt;/code> and the &lt;code>field&lt;/code> setting defines the numeric field of
the documents the average will be computed on. The above will return the
following:&lt;/p></description></item><item><title>Cardinality aggregation</title><link>/docs/references/aggregation/metric/cardinality/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/references/aggregation/metric/cardinality/</guid><description>&lt;h1 id="cardinality-aggregation">
 Cardinality aggregation
 &lt;a class="anchor" href="#cardinality-aggregation">#&lt;/a>
&lt;/h1>
&lt;p>A single-value metrics aggregation that counts the number of distinct
(approximate) values of a field.&lt;/p>
&lt;h2 id="examples">
 Examples
 &lt;a class="anchor" href="#examples">#&lt;/a>
&lt;/h2>
&lt;div class="pizza-playground" data-dataset="sales" data-dsl="{
 &amp;#34;size&amp;#34;: 0,
 &amp;#34;aggs&amp;#34;: {
 &amp;#34;types&amp;#34;: {
 &amp;#34;cardinality&amp;#34;: {
 &amp;#34;field&amp;#34;: &amp;#34;type&amp;#34;
 }
 }
 }
}">
 &lt;noscript>JavaScript is disabled — use the curl form of this example instead.&lt;/noscript>
&lt;/div>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-sh" data-lang="sh">&lt;span class="line">&lt;span class="cl">POST /sales/_search
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;aggs&amp;#34;&lt;/span>: &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;type_count&amp;#34;&lt;/span>: &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;cardinality&amp;#34;&lt;/span>: &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;field&amp;#34;&lt;/span>: &lt;span class="s2">&amp;#34;type&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Response:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-sh" data-lang="sh">&lt;span class="line">&lt;span class="cl">&lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> ...
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;aggregations&amp;#34;&lt;/span>: &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;type_count&amp;#34;&lt;/span>: &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;value&amp;#34;&lt;/span>: &lt;span class="m">3&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="parameters-for-cardinality">
 Parameters for &lt;code>cardinality&lt;/code>
 &lt;a class="anchor" href="#parameters-for-cardinality">#&lt;/a>
&lt;/h2>
&lt;ul>
&lt;li>&lt;code>field&lt;/code> &lt;br>
(Required, string) Field you wish to aggregate.&lt;/li>
&lt;li>&lt;code>missing&lt;/code> &lt;br>
(Optional, value) Value used for documents missing the field; all
such documents count as one distinct value.&lt;/li>
&lt;/ul></description></item><item><title>Max aggregation</title><link>/docs/references/aggregation/metric/max/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/references/aggregation/metric/max/</guid><description>&lt;h1 id="max-aggregation">
 Max aggregation
 &lt;a class="anchor" href="#max-aggregation">#&lt;/a>
&lt;/h1>
&lt;p>A single-value metrics aggregation that keeps track and returns the maximum
value among the numeric values extracted from the aggregated documents.&lt;/p>
&lt;h2 id="examples">
 Examples
 &lt;a class="anchor" href="#examples">#&lt;/a>
&lt;/h2>
&lt;p>Computing the max price value across all documents:&lt;/p>
&lt;div class="pizza-playground" data-dataset="sales" data-dsl="{
 &amp;#34;size&amp;#34;: 0,
 &amp;#34;aggs&amp;#34;: {
 &amp;#34;max_price&amp;#34;: {
 &amp;#34;max&amp;#34;: {
 &amp;#34;field&amp;#34;: &amp;#34;price&amp;#34;
 }
 }
 }
}">
 &lt;noscript>JavaScript is disabled — use the curl form of this example instead.&lt;/noscript>
&lt;/div>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-sh" data-lang="sh">&lt;span class="line">&lt;span class="cl">POST /sales/_search
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;aggs&amp;#34;&lt;/span>: &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;max_price&amp;#34;&lt;/span>: &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;max&amp;#34;&lt;/span>: &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;field&amp;#34;&lt;/span>: &lt;span class="s2">&amp;#34;price&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Response:&lt;/p></description></item><item><title>Min aggregation</title><link>/docs/references/aggregation/metric/min/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/references/aggregation/metric/min/</guid><description>&lt;h1 id="min-aggregation">
 Min aggregation
 &lt;a class="anchor" href="#min-aggregation">#&lt;/a>
&lt;/h1>
&lt;p>A single-value metrics aggregation that keeps track and returns the minimum
value among numeric values extracted from the aggregated documents.&lt;/p>
&lt;h2 id="examples">
 Examples
 &lt;a class="anchor" href="#examples">#&lt;/a>
&lt;/h2>
&lt;p>Computing the min price value across all documents:&lt;/p>
&lt;div class="pizza-playground" data-dataset="sales" data-dsl="{
 &amp;#34;size&amp;#34;: 0,
 &amp;#34;aggs&amp;#34;: {
 &amp;#34;min_price&amp;#34;: {
 &amp;#34;min&amp;#34;: {
 &amp;#34;field&amp;#34;: &amp;#34;price&amp;#34;
 }
 }
 }
}">
 &lt;noscript>JavaScript is disabled — use the curl form of this example instead.&lt;/noscript>
&lt;/div>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-sh" data-lang="sh">&lt;span class="line">&lt;span class="cl">POST /sales/_search
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;aggs&amp;#34;&lt;/span>: &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;min_price&amp;#34;&lt;/span>: &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;min&amp;#34;&lt;/span>: &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;field&amp;#34;&lt;/span>: &lt;span class="s2">&amp;#34;price&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Response:&lt;/p></description></item><item><title>Sum aggregation</title><link>/docs/references/aggregation/metric/sum/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/references/aggregation/metric/sum/</guid><description>&lt;h1 id="sum-aggregation">
 Sum aggregation
 &lt;a class="anchor" href="#sum-aggregation">#&lt;/a>
&lt;/h1>
&lt;p>A single-value metrics aggregation that sums up numeric values that are
extracted from the aggregated documents.&lt;/p>
&lt;h2 id="examples">
 Examples
 &lt;a class="anchor" href="#examples">#&lt;/a>
&lt;/h2>
&lt;p>Assuming the data consists of documents representing sales records we can sum
the sale price of all hats with:&lt;/p>
&lt;div class="pizza-playground" data-dataset="sales" data-dsl="{
 &amp;#34;size&amp;#34;: 0,
 &amp;#34;aggs&amp;#34;: {
 &amp;#34;hat_revenue&amp;#34;: {
 &amp;#34;filter&amp;#34;: {
 &amp;#34;term&amp;#34;: {
 &amp;#34;field&amp;#34;: &amp;#34;type&amp;#34;,
 &amp;#34;value&amp;#34;: &amp;#34;hat&amp;#34;
 }
 },
 &amp;#34;aggs&amp;#34;: {
 &amp;#34;total&amp;#34;: {
 &amp;#34;sum&amp;#34;: {
 &amp;#34;field&amp;#34;: &amp;#34;price&amp;#34;
 }
 }
 }
 }
 }
}">
 &lt;noscript>JavaScript is disabled — use the curl form of this example instead.&lt;/noscript>
&lt;/div>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-sh" data-lang="sh">&lt;span class="line">&lt;span class="cl">POST /sales/_search
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;query&amp;#34;&lt;/span>: &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;term&amp;#34;&lt;/span>: &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;field&amp;#34;&lt;/span>: &lt;span class="s2">&amp;#34;type&amp;#34;&lt;/span>,
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;value&amp;#34;&lt;/span>: &lt;span class="s2">&amp;#34;hat&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>,
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;aggs&amp;#34;&lt;/span>: &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;hat_prices&amp;#34;&lt;/span>: &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;sum&amp;#34;&lt;/span>: &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;field&amp;#34;&lt;/span>: &lt;span class="s2">&amp;#34;price&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Resulting in:&lt;/p></description></item><item><title>Value count aggregation</title><link>/docs/references/aggregation/metric/value-count/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/references/aggregation/metric/value-count/</guid><description>&lt;h1 id="value-count-aggregation">
 Value count aggregation
 &lt;a class="anchor" href="#value-count-aggregation">#&lt;/a>
&lt;/h1>
&lt;p>A single-value metrics aggregation that counts the number of values that are
extracted from the aggregated documents. Typically, this aggregator will be used
in conjunction with other single-value aggregations. For example, when computing
the &lt;code>avg&lt;/code> one might be interested in the number of values the average is
computed over.&lt;/p>
&lt;p>&lt;code>value_count&lt;/code> does not de-duplicate values, so even if a field has duplicates
each value will be counted individually.&lt;/p></description></item><item><title>Median absolute deviation aggregation</title><link>/docs/references/aggregation/metric/median-absolute-deviation/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/references/aggregation/metric/median-absolute-deviation/</guid><description>&lt;h1 id="median-absolute-deviation-aggregation">
 Median absolute deviation aggregation
 &lt;a class="anchor" href="#median-absolute-deviation-aggregation">#&lt;/a>
&lt;/h1>
&lt;p>A single-value metrics aggregation that computes the median absolute
deviation — the median of the distances from each value to the median of
all values. A robust measure of spread: unlike standard deviation it is
not skewed by a few extreme values.&lt;/p>
&lt;h2 id="example">
 Example
 &lt;a class="anchor" href="#example">#&lt;/a>
&lt;/h2>
&lt;p>Sales prices take only four values (&lt;code>15&lt;/code>, &lt;code>30&lt;/code>, &lt;code>45&lt;/code>, &lt;code>60&lt;/code>), so half the
documents sit at &lt;code>15&lt;/code> and the deviation of a typical document is small:&lt;/p></description></item><item><title>Weighted average aggregation</title><link>/docs/references/aggregation/metric/weighted-avg/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/references/aggregation/metric/weighted-avg/</guid><description>&lt;h1 id="weighted-average-aggregation">
 Weighted average aggregation
 &lt;a class="anchor" href="#weighted-average-aggregation">#&lt;/a>
&lt;/h1>
&lt;p>A single-value metrics aggregation that computes the weighted average of
numeric values. Each document contributes &lt;code>value × weight&lt;/code>, divided by
the total weight — e.g. an average price weighted by quantity sold.&lt;/p>
&lt;h2 id="example">
 Example
 &lt;a class="anchor" href="#example">#&lt;/a>
&lt;/h2>
&lt;p>Average unit &lt;code>price&lt;/code> weighted by &lt;code>qty&lt;/code> (larger purchases count more):&lt;/p>
&lt;div class="pizza-playground" data-dataset="sales" data-dsl="{
 &amp;#34;size&amp;#34;: 0,
 &amp;#34;aggs&amp;#34;: {
 &amp;#34;weighted_price&amp;#34;: {
 &amp;#34;weighted_avg&amp;#34;: {
 &amp;#34;value&amp;#34;: { &amp;#34;field&amp;#34;: &amp;#34;price&amp;#34; },
 &amp;#34;weight&amp;#34;: { &amp;#34;field&amp;#34;: &amp;#34;qty&amp;#34; }
 }
 }
 }
}">
 &lt;noscript>JavaScript is disabled — use the curl form of this example instead.&lt;/noscript>
&lt;/div>
&lt;p>The plain 
 &lt;a href="/docs/references/aggregation/metric/avg/">&lt;code>avg&lt;/code>&lt;/a> of &lt;code>price&lt;/code> is &lt;code>27.5&lt;/code>; quantity-weighted it is
&lt;code>28.125&lt;/code>.&lt;/p></description></item><item><title>Stats aggregation</title><link>/docs/references/aggregation/metric/stats/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/references/aggregation/metric/stats/</guid><description>&lt;h1 id="stats-aggregation">
 Stats aggregation
 &lt;a class="anchor" href="#stats-aggregation">#&lt;/a>
&lt;/h1>
&lt;p>A multi-value metrics aggregation that computes basic statistics
(&lt;code>min&lt;/code>, &lt;code>max&lt;/code>, &lt;code>sum&lt;/code>, &lt;code>count&lt;/code>, &lt;code>avg&lt;/code>) over numeric values extracted from
the aggregated documents.&lt;/p>
&lt;h2 id="examples">
 Examples
 &lt;a class="anchor" href="#examples">#&lt;/a>
&lt;/h2>
&lt;div class="pizza-playground" data-dataset="sales" data-dsl="{
 &amp;#34;size&amp;#34;: 0,
 &amp;#34;aggs&amp;#34;: {
 &amp;#34;price_stats&amp;#34;: {
 &amp;#34;stats&amp;#34;: {
 &amp;#34;field&amp;#34;: &amp;#34;price&amp;#34;
 }
 }
 }
}">
 &lt;noscript>JavaScript is disabled — use the curl form of this example instead.&lt;/noscript>
&lt;/div>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-sh" data-lang="sh">&lt;span class="line">&lt;span class="cl">POST /sales/_search
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;aggs&amp;#34;&lt;/span>: &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;prices_stats&amp;#34;&lt;/span>: &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;stats&amp;#34;&lt;/span>: &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;field&amp;#34;&lt;/span>: &lt;span class="s2">&amp;#34;price&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Response:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-sh" data-lang="sh">&lt;span class="line">&lt;span class="cl">&lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> ...
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;aggregations&amp;#34;&lt;/span>: &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;prices_stats&amp;#34;&lt;/span>: &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;count&amp;#34;&lt;/span>: 9,
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;min&amp;#34;&lt;/span>: 72.0,
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;max&amp;#34;&lt;/span>: 99.0,
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;avg&amp;#34;&lt;/span>: 86.0,
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;sum&amp;#34;&lt;/span>: 774.0
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="parameters-for-stats">
 Parameters for &lt;code>stats&lt;/code>
 &lt;a class="anchor" href="#parameters-for-stats">#&lt;/a>
&lt;/h2>
&lt;ul>
&lt;li>&lt;code>field&lt;/code> &lt;br>
(Required, string) Field you wish to aggregate.&lt;/li>
&lt;li>&lt;code>missing&lt;/code> &lt;br>
(Optional, value) Value used for documents missing the field.&lt;/li>
&lt;/ul>
&lt;p>&lt;code>extended_stats&lt;/code> takes the same parameters and additionally returns
variance, standard deviation and related statistics.&lt;/p></description></item><item><title>Extended stats aggregation</title><link>/docs/references/aggregation/metric/extended-stats/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/references/aggregation/metric/extended-stats/</guid><description>&lt;h1 id="extended-stats-aggregation">
 Extended stats aggregation
 &lt;a class="anchor" href="#extended-stats-aggregation">#&lt;/a>
&lt;/h1>
&lt;p>A multi-value metrics aggregation extending 
 &lt;a href="/docs/references/aggregation/metric/stats/">&lt;code>stats&lt;/code>&lt;/a> with
squares, variance, standard deviation and their lower/upper bounds.&lt;/p>
&lt;h2 id="example">
 Example
 &lt;a class="anchor" href="#example">#&lt;/a>
&lt;/h2>
&lt;div class="pizza-playground" data-dataset="sales" data-dsl="{
 &amp;#34;size&amp;#34;: 0,
 &amp;#34;aggs&amp;#34;: {
 &amp;#34;price_stats&amp;#34;: {
 &amp;#34;extended_stats&amp;#34;: {
 &amp;#34;field&amp;#34;: &amp;#34;price&amp;#34;
 }
 }
 }
}">
 &lt;noscript>JavaScript is disabled — use the curl form of this example instead.&lt;/noscript>
&lt;/div>
&lt;p>Returns &lt;code>count&lt;/code>, &lt;code>min&lt;/code>, &lt;code>max&lt;/code>, &lt;code>avg&lt;/code>, &lt;code>sum&lt;/code>, &lt;code>sum_of_squares&lt;/code>, &lt;code>variance&lt;/code>,
&lt;code>variance_population&lt;/code>, &lt;code>variance_sampling&lt;/code>, &lt;code>std_deviation&lt;/code>,
&lt;code>std_deviation_population&lt;/code>, &lt;code>std_deviation_sampling&lt;/code> plus
&lt;code>std_deviation_bounds&lt;/code> (upper/lower at ±2σ).&lt;/p>
&lt;h2 id="parameters-for-extended_stats">
 Parameters for &lt;code>extended_stats&lt;/code>
 &lt;a class="anchor" href="#parameters-for-extended_stats">#&lt;/a>
&lt;/h2>
&lt;ul>
&lt;li>&lt;code>field&lt;/code> &lt;br>
(Required, string) Numeric field you wish to aggregate.&lt;/li>
&lt;li>&lt;code>sigma&lt;/code> &lt;br>
(Optional, float, default: &lt;code>2&lt;/code>) Multiplier for the standard deviation
bounds.&lt;/li>
&lt;/ul></description></item><item><title>Percentiles aggregation</title><link>/docs/references/aggregation/metric/percentiles/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/references/aggregation/metric/percentiles/</guid><description>&lt;h1 id="percentiles-aggregation">
 Percentiles aggregation
 &lt;a class="anchor" href="#percentiles-aggregation">#&lt;/a>
&lt;/h1>
&lt;p>A multi-value metrics aggregation that calculates one or more percentiles over
numeric values extracted from the aggregated documents.&lt;/p>
&lt;p>Percentiles show the point at which a certain percentage of observed values
occur. For example, the 95th percentile is the value which is greater than 95%
of the observed values.&lt;/p>
&lt;p>Percentiles are often used to find outliers. In normal distributions, the 0.13th
and 99.87th percentiles represents three standard deviations from the mean. Any
data which falls outside three standard deviations is often considered an
anomaly.&lt;/p></description></item><item><title>Percentile ranks aggregation</title><link>/docs/references/aggregation/metric/percentile-ranks/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/references/aggregation/metric/percentile-ranks/</guid><description>&lt;h1 id="percentile-ranks-aggregation">
 Percentile ranks aggregation
 &lt;a class="anchor" href="#percentile-ranks-aggregation">#&lt;/a>
&lt;/h1>
&lt;p>A multi-value metrics aggregation that answers the inverse of

 &lt;a href="/docs/references/aggregation/metric/percentiles/">&lt;code>percentiles&lt;/code>&lt;/a>: for each value you provide, what
percentage of documents is at or below it.&lt;/p>
&lt;h2 id="example">
 Example
 &lt;a class="anchor" href="#example">#&lt;/a>
&lt;/h2>
&lt;p>Where do the prices &lt;code>30&lt;/code> and &lt;code>45&lt;/code> sit in the distribution?&lt;/p>
&lt;div class="pizza-playground" data-dataset="sales" data-dsl="{
 &amp;#34;size&amp;#34;: 0,
 &amp;#34;aggs&amp;#34;: {
 &amp;#34;price_ranks&amp;#34;: {
 &amp;#34;percentile_ranks&amp;#34;: {
 &amp;#34;field&amp;#34;: &amp;#34;price&amp;#34;,
 &amp;#34;values&amp;#34;: [30, 45]
 }
 }
 }
}">
 &lt;noscript>JavaScript is disabled — use the curl form of this example instead.&lt;/noscript>
&lt;/div>
&lt;p>&lt;code>30&lt;/code> is at rank &lt;code>75&lt;/code> (75% of documents cost 30 or less), &lt;code>45&lt;/code> at
&lt;code>≈91.7&lt;/code>.&lt;/p></description></item><item><title>Boxplot aggregation</title><link>/docs/references/aggregation/metric/boxplot/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/references/aggregation/metric/boxplot/</guid><description>&lt;h1 id="boxplot-aggregation">
 Boxplot aggregation
 &lt;a class="anchor" href="#boxplot-aggregation">#&lt;/a>
&lt;/h1>
&lt;p>A multi-value metrics aggregation producing the five-number summary of a
distribution: minimum, lower quartile (q1), median (q2), upper quartile
(q3) and maximum, plus whiskers.&lt;/p>
&lt;h2 id="example">
 Example
 &lt;a class="anchor" href="#example">#&lt;/a>
&lt;/h2>
&lt;div class="pizza-playground" data-dataset="sales" data-dsl="{
 &amp;#34;size&amp;#34;: 0,
 &amp;#34;aggs&amp;#34;: {
 &amp;#34;price_box&amp;#34;: {
 &amp;#34;boxplot&amp;#34;: {
 &amp;#34;field&amp;#34;: &amp;#34;price&amp;#34;
 }
 }
 }
}">
 &lt;noscript>JavaScript is disabled — use the curl form of this example instead.&lt;/noscript>
&lt;/div>
&lt;p>For the four-price dataset: &lt;code>min&lt;/code> 15, &lt;code>q1&lt;/code> 15, &lt;code>q2&lt;/code> 22.5, &lt;code>q3&lt;/code> 37.5,
&lt;code>max&lt;/code> 60, with &lt;code>lower&lt;/code>/&lt;code>upper&lt;/code> whiskers at the data extremes.&lt;/p></description></item><item><title>String stats aggregation</title><link>/docs/references/aggregation/metric/string-stats/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/references/aggregation/metric/string-stats/</guid><description>&lt;h1 id="string-stats-aggregation">
 String stats aggregation
 &lt;a class="anchor" href="#string-stats-aggregation">#&lt;/a>
&lt;/h1>
&lt;p>A multi-value metrics aggregation computing length and character
statistics over keyword/string values: count, min/max/avg length and
Shannon entropy of the character distribution.&lt;/p>
&lt;h2 id="example">
 Example
 &lt;a class="anchor" href="#example">#&lt;/a>
&lt;/h2>
&lt;div class="pizza-playground" data-dataset="sales" data-dsl="{
 &amp;#34;size&amp;#34;: 0,
 &amp;#34;aggs&amp;#34;: {
 &amp;#34;type_stats&amp;#34;: {
 &amp;#34;string_stats&amp;#34;: {
 &amp;#34;field&amp;#34;: &amp;#34;type&amp;#34;
 }
 }
 }
}">
 &lt;noscript>JavaScript is disabled — use the curl form of this example instead.&lt;/noscript>
&lt;/div>
&lt;p>Four product types (&lt;code>t-shirt&lt;/code> 7 chars ×60, &lt;code>hat&lt;/code> 3 ×30, &lt;code>mug&lt;/code> 3 ×20,
&lt;code>sticker&lt;/code> 7 ×10): count 120, min_length 3, max_length 7, avg_length
≈5.33.&lt;/p></description></item><item><title>Matrix stats aggregation</title><link>/docs/references/aggregation/metric/matrix-stats/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/references/aggregation/metric/matrix-stats/</guid><description>&lt;h1 id="matrix-stats-aggregation">
 Matrix stats aggregation
 &lt;a class="anchor" href="#matrix-stats-aggregation">#&lt;/a>
&lt;/h1>
&lt;p>A multi-value metrics aggregation computing counts, means, variances,
skewness, kurtosis and the correlation matrix across several numeric
fields at once.&lt;/p>
&lt;h2 id="example">
 Example
 &lt;a class="anchor" href="#example">#&lt;/a>
&lt;/h2>
&lt;div class="pizza-playground" data-dataset="sales" data-dsl="{
 &amp;#34;size&amp;#34;: 0,
 &amp;#34;aggs&amp;#34;: {
 &amp;#34;num_matrix&amp;#34;: {
 &amp;#34;matrix_stats&amp;#34;: {
 &amp;#34;fields&amp;#34;: [&amp;#34;price&amp;#34;, &amp;#34;qty&amp;#34;, &amp;#34;amount&amp;#34;]
 }
 }
 }
}">
 &lt;noscript>JavaScript is disabled — use the curl form of this example instead.&lt;/noscript>
&lt;/div>
&lt;p>&lt;code>amount&lt;/code> is derived from &lt;code>price × qty&lt;/code>, so their correlation is ~1 — the
matrix makes such relationships visible at a glance.&lt;/p></description></item><item><title>T-test aggregation</title><link>/docs/references/aggregation/metric/t-test/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/references/aggregation/metric/t-test/</guid><description>&lt;h1 id="t-test-aggregation">
 T-test aggregation
 &lt;a class="anchor" href="#t-test-aggregation">#&lt;/a>
&lt;/h1>
&lt;p>A single-value metrics aggregation for a paired or two-sample Student&amp;rsquo;s
t-test over two numeric fields. Positive values mean &lt;code>a&lt;/code> tends to be
larger than &lt;code>b&lt;/code>.&lt;/p>
&lt;blockquote>
&lt;p>Simplified engine note: the paired form (&lt;code>type: paired&lt;/code>) is computed
over the per-document column values; &lt;code>homoscedastic&lt;/code> /
&lt;code>heteroscedastic&lt;/code> fall back to the same paired evaluation.&lt;/p>
&lt;/blockquote>
&lt;h2 id="example">
 Example
 &lt;a class="anchor" href="#example">#&lt;/a>
&lt;/h2>
&lt;p>Do sale prices differ from quantities in a systematic way?&lt;/p>
&lt;div class="pizza-playground" data-dataset="sales" data-dsl="{
 &amp;#34;size&amp;#34;: 0,
 &amp;#34;aggs&amp;#34;: {
 &amp;#34;price_vs_qty&amp;#34;: {
 &amp;#34;t_test&amp;#34;: {
 &amp;#34;a&amp;#34;: { &amp;#34;field&amp;#34;: &amp;#34;price&amp;#34; },
 &amp;#34;b&amp;#34;: { &amp;#34;field&amp;#34;: &amp;#34;qty&amp;#34; },
 &amp;#34;type&amp;#34;: &amp;#34;paired&amp;#34;
 }
 }
 }
}">
 &lt;noscript>JavaScript is disabled — use the curl form of this example instead.&lt;/noscript>
&lt;/div>
&lt;h2 id="parameters-for-t_test">
 Parameters for &lt;code>t_test&lt;/code>
 &lt;a class="anchor" href="#parameters-for-t_test">#&lt;/a>
&lt;/h2>
&lt;ul>
&lt;li>&lt;code>a&lt;/code> &lt;br>
(Required, object) &lt;code>field&lt;/code> — the first numeric field.&lt;/li>
&lt;li>&lt;code>b&lt;/code> &lt;br>
(Required, object) &lt;code>field&lt;/code> — the second numeric field.&lt;/li>
&lt;li>&lt;code>type&lt;/code> &lt;br>
(Optional, string, default: &lt;code>paired&lt;/code>) &lt;code>paired&lt;/code>, &lt;code>homoscedastic&lt;/code> or
&lt;code>heteroscedastic&lt;/code>.&lt;/li>
&lt;/ul></description></item><item><title>Rate aggregation</title><link>/docs/references/aggregation/metric/rate/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/references/aggregation/metric/rate/</guid><description>&lt;h1 id="rate-aggregation">
 Rate aggregation
 &lt;a class="anchor" href="#rate-aggregation">#&lt;/a>
&lt;/h1>
&lt;p>A single-value metrics aggregation that sums a numeric field, intended
for counters and rates inside 
 &lt;a href="/docs/references/aggregation/bucket/date-histogram/">&lt;code>date_histogram&lt;/code>&lt;/a>
buckets (per-interval totals).&lt;/p>
&lt;h2 id="example">
 Example
 &lt;a class="anchor" href="#example">#&lt;/a>
&lt;/h2>
&lt;div class="pizza-playground" data-dataset="sales" data-dsl="{
 &amp;#34;size&amp;#34;: 0,
 &amp;#34;aggs&amp;#34;: {
 &amp;#34;amount_rate&amp;#34;: {
 &amp;#34;rate&amp;#34;: {
 &amp;#34;field&amp;#34;: &amp;#34;amount&amp;#34;
 }
 }
 }
}">
 &lt;noscript>JavaScript is disabled — use the curl form of this example instead.&lt;/noscript>
&lt;/div>
&lt;p>Outside a histogram, &lt;code>rate&lt;/code> equals 
 &lt;a href="/docs/references/aggregation/metric/sum/">&lt;code>sum&lt;/code>&lt;/a> — here the total
&lt;code>amount&lt;/code>, &lt;code>6750&lt;/code>. Inside a &lt;code>date_histogram&lt;/code> it returns each bucket&amp;rsquo;s
total.&lt;/p></description></item><item><title>Geo bounds aggregation</title><link>/docs/references/aggregation/metric/geo-bounds/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/references/aggregation/metric/geo-bounds/</guid><description>&lt;h1 id="geo-bounds-aggregation">
 Geo bounds aggregation
 &lt;a class="anchor" href="#geo-bounds-aggregation">#&lt;/a>
&lt;/h1>
&lt;p>A metrics aggregation computing the bounding box (top-left /
bottom-right corners) of all &lt;code>geo_point&lt;/code> values.&lt;/p>
&lt;h2 id="example">
 Example
 &lt;a class="anchor" href="#example">#&lt;/a>
&lt;/h2>
&lt;div class="pizza-playground" data-dataset="places" data-dsl="{
 &amp;#34;size&amp;#34;: 0,
 &amp;#34;aggs&amp;#34;: {
 &amp;#34;map_bounds&amp;#34;: {
 &amp;#34;geo_bounds&amp;#34;: {
 &amp;#34;field&amp;#34;: &amp;#34;location&amp;#34;
 }
 }
 }
}">
 &lt;noscript>JavaScript is disabled — use the curl form of this example instead.&lt;/noscript>
&lt;/div>
&lt;p>Returns the &lt;code>bounds&lt;/code> wrapping all 15 places — the box you would fit a
map viewport to.&lt;/p>
&lt;h2 id="parameters-for-geo_bounds">
 Parameters for &lt;code>geo_bounds&lt;/code>
 &lt;a class="anchor" href="#parameters-for-geo_bounds">#&lt;/a>
&lt;/h2>
&lt;ul>
&lt;li>&lt;code>field&lt;/code> &lt;br>
(Required, string) &lt;code>geo_point&lt;/code> field you wish to aggregate.&lt;/li>
&lt;li>&lt;code>wrap_longitude&lt;/code> &lt;br>
(Optional, boolean, default: &lt;code>true&lt;/code>) Allow the box to wrap the
antimeridian.&lt;/li>
&lt;/ul></description></item><item><title>Geo centroid aggregation</title><link>/docs/references/aggregation/metric/geo-centroid/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/references/aggregation/metric/geo-centroid/</guid><description>&lt;h1 id="geo-centroid-aggregation">
 Geo centroid aggregation
 &lt;a class="anchor" href="#geo-centroid-aggregation">#&lt;/a>
&lt;/h1>
&lt;p>A metrics aggregation computing the weighted centroid (mean latitude and
longitude) of all &lt;code>geo_point&lt;/code> values.&lt;/p>
&lt;h2 id="example">
 Example
 &lt;a class="anchor" href="#example">#&lt;/a>
&lt;/h2>
&lt;div class="pizza-playground" data-dataset="places" data-dsl="{
 &amp;#34;size&amp;#34;: 0,
 &amp;#34;aggs&amp;#34;: {
 &amp;#34;map_center&amp;#34;: {
 &amp;#34;geo_centroid&amp;#34;: {
 &amp;#34;field&amp;#34;: &amp;#34;location&amp;#34;
 }
 }
 }
}">
 &lt;noscript>JavaScript is disabled — use the curl form of this example instead.&lt;/noscript>
&lt;/div>
&lt;p>Returns the &lt;code>count&lt;/code> of points and their centroid — the natural center
point for map placement.&lt;/p>
&lt;h2 id="parameters-for-geo_centroid">
 Parameters for &lt;code>geo_centroid&lt;/code>
 &lt;a class="anchor" href="#parameters-for-geo_centroid">#&lt;/a>
&lt;/h2>
&lt;ul>
&lt;li>&lt;code>field&lt;/code> &lt;br>
(Required, string) &lt;code>geo_point&lt;/code> field you wish to aggregate.&lt;/li>
&lt;/ul></description></item><item><title>Top hits aggregation</title><link>/docs/references/aggregation/metric/top-hits/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/references/aggregation/metric/top-hits/</guid><description>&lt;h1 id="top-hits-aggregation">
 Top hits aggregation
 &lt;a class="anchor" href="#top-hits-aggregation">#&lt;/a>
&lt;/h1>
&lt;p>Keeps track of the most relevant documents being aggregated — useful
inside a bucket aggregation (e.g. &lt;code>terms&lt;/code>) to return the best-matching
documents per bucket.&lt;/p>
&lt;h2 id="examples">
 Examples
 &lt;a class="anchor" href="#examples">#&lt;/a>
&lt;/h2>
&lt;p>Top 3 sales per merchant:&lt;/p>
&lt;div class="pizza-playground" data-dataset="sales" data-dsl="{
 &amp;#34;size&amp;#34;: 0,
 &amp;#34;aggs&amp;#34;: {
 &amp;#34;top&amp;#34;: {
 &amp;#34;top_hits&amp;#34;: {
 &amp;#34;size&amp;#34;: 3,
 &amp;#34;sort&amp;#34;: [
 {
 &amp;#34;field&amp;#34;: &amp;#34;amount&amp;#34;,
 &amp;#34;order&amp;#34;: &amp;#34;desc&amp;#34;
 }
 ]
 }
 }
 }
}">
 &lt;noscript>JavaScript is disabled — use the curl form of this example instead.&lt;/noscript>
&lt;/div>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-sh" data-lang="sh">&lt;span class="line">&lt;span class="cl">POST /sales/_search
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;aggs&amp;#34;&lt;/span>: &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;top_merchants&amp;#34;&lt;/span>: &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;terms&amp;#34;&lt;/span>: &lt;span class="o">{&lt;/span> &lt;span class="s2">&amp;#34;field&amp;#34;&lt;/span>: &lt;span class="s2">&amp;#34;merchant&amp;#34;&lt;/span> &lt;span class="o">}&lt;/span>,
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;aggs&amp;#34;&lt;/span>: &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;top_sales&amp;#34;&lt;/span>: &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;top_hits&amp;#34;&lt;/span>: &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;size&amp;#34;&lt;/span>: 3,
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;sort&amp;#34;&lt;/span>: &lt;span class="o">[{&lt;/span> &lt;span class="s2">&amp;#34;field&amp;#34;&lt;/span>: &lt;span class="s2">&amp;#34;amount&amp;#34;&lt;/span>, &lt;span class="s2">&amp;#34;order&amp;#34;&lt;/span>: &lt;span class="s2">&amp;#34;desc&amp;#34;&lt;/span> &lt;span class="o">}]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="parameters-for-top_hits">
 Parameters for &lt;code>top_hits&lt;/code>
 &lt;a class="anchor" href="#parameters-for-top_hits">#&lt;/a>
&lt;/h2>
&lt;ul>
&lt;li>&lt;code>size&lt;/code> &lt;br>
(Optional, integer, default: &lt;code>3&lt;/code>) Number of top hits to return per
bucket.&lt;/li>
&lt;li>&lt;code>sort&lt;/code> &lt;br>
(Optional) Sort order for the top hits. Accepts &lt;code>&amp;quot;field&amp;quot;&lt;/code>,
&lt;code>[&amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;]&lt;/code> and &lt;code>[{ &amp;quot;field&amp;quot;: &amp;quot;asc&amp;quot; }]&lt;/code> forms — all normalize to an
object array.&lt;/li>
&lt;li>&lt;code>_source&lt;/code> &lt;br>
(Optional) Fields to include in the returned source. If empty, the
full source is returned.&lt;/li>
&lt;/ul></description></item><item><title>Top metrics aggregation</title><link>/docs/references/aggregation/metric/top-metrics/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/references/aggregation/metric/top-metrics/</guid><description>&lt;h1 id="top-metrics-aggregation">
 Top metrics aggregation
 &lt;a class="anchor" href="#top-metrics-aggregation">#&lt;/a>
&lt;/h1>
&lt;p>A metrics aggregation that returns metric values from the leading
matching documents — a cheaper alternative to 
 &lt;a href="/docs/references/aggregation/metric/top-hits/">&lt;code>top_hits&lt;/code>&lt;/a>
when you only need field values, not whole documents.&lt;/p>
&lt;blockquote>
&lt;p>Engine note: &lt;code>sort&lt;/code> is accepted for compatibility; the current
implementation returns the metrics of the first &lt;code>size&lt;/code> matching
documents.&lt;/p>
&lt;/blockquote>
&lt;h2 id="example">
 Example
 &lt;a class="anchor" href="#example">#&lt;/a>
&lt;/h2>
&lt;div class="pizza-playground" data-dataset="sales" data-dsl="{
 &amp;#34;size&amp;#34;: 0,
 &amp;#34;aggs&amp;#34;: {
 &amp;#34;top_price&amp;#34;: {
 &amp;#34;top_metrics&amp;#34;: {
 &amp;#34;metrics&amp;#34;: [{ &amp;#34;field&amp;#34;: &amp;#34;price&amp;#34; }],
 &amp;#34;sort&amp;#34;: [{ &amp;#34;field&amp;#34;: &amp;#34;price&amp;#34;, &amp;#34;order&amp;#34;: &amp;#34;desc&amp;#34; }]
 }
 }
 }
}">
 &lt;noscript>JavaScript is disabled — use the curl form of this example instead.&lt;/noscript>
&lt;/div>
&lt;h2 id="parameters-for-top_metrics">
 Parameters for &lt;code>top_metrics&lt;/code>
 &lt;a class="anchor" href="#parameters-for-top_metrics">#&lt;/a>
&lt;/h2>
&lt;ul>
&lt;li>&lt;code>metrics&lt;/code> &lt;br>
(Required, object array) &lt;code>field&lt;/code> entries whose values are returned.&lt;/li>
&lt;li>&lt;code>sort&lt;/code> &lt;br>
(Optional, array) Sort clause selecting the &amp;ldquo;top&amp;rdquo; documents.&lt;/li>
&lt;li>&lt;code>size&lt;/code> &lt;br>
(Optional, integer, default: &lt;code>1&lt;/code>) How many top entries to return.&lt;/li>
&lt;/ul></description></item></channel></rss>