<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Bucket_script on INFINI Pizza</title><link>https://pizza.rs/tags/bucket_script/</link><description>Recent content in Bucket_script on INFINI Pizza</description><generator>Hugo</generator><language>en</language><atom:link href="https://pizza.rs/tags/bucket_script/index.xml" rel="self" type="application/rss+xml"/><item><title>Bucket script aggregation</title><link>https://pizza.rs/docs/references/aggregation/pipeline/bucket-script/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://pizza.rs/docs/references/aggregation/pipeline/bucket-script/</guid><description>&lt;h1 id="bucket-script-aggregation">
 Bucket script aggregation
 &lt;a class="anchor" href="#bucket-script-aggregation">#&lt;/a>
&lt;/h1>
&lt;p>A parent pipeline aggregation computing &lt;strong>arithmetic on a bucket&amp;rsquo;s own
metrics&lt;/strong> — the script references sibling metrics by name through
&lt;code>params&lt;/code> and its result becomes a new per-bucket value. It is the
SQL &lt;code>SELECT a / b AS c&lt;/code> of the aggregation world: one derived column,
evaluated once per bucket over values the bucket already holds.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="s2">&amp;#34;avg_order&amp;#34;&lt;/span>&lt;span class="err">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;bucket_script&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;buckets_path&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nt">&amp;#34;r&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;revenue&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nt">&amp;#34;n&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;orders&amp;#34;&lt;/span> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;script&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;params.r / params.n&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="how-it-works">
 How it works
 &lt;a class="anchor" href="#how-it-works">#&lt;/a>
&lt;/h2>
&lt;p>&lt;code>bucket_script&lt;/code> is declared &lt;strong>inside&lt;/strong> the multi-bucket aggregation it
decorates, next to the metrics it consumes. After the buckets are
built, the engine resolves each named path against every bucket,
binds the numbers into the script&amp;rsquo;s scope, evaluates the script once,
and inserts its result under the pipeline&amp;rsquo;s own name — the
response shape &lt;code>buckets[i].avg_order.value&lt;/code>.&lt;/p></description></item></channel></rss>