<p dir="auto">Hi,</p>
<p dir="auto">Should be great to be able to perform a grouping of computed values using the pipeline aggregation range bucket.</p>
<p dir="auto">Thanks,</p>
<p dir="auto">David</p>
<p dir="auto">Let's say the data set is transactions made by users and the question we want to ask is "Which users have transactions totalling between 100 - 200, 200 - 300, etc.?"</p>
<p dir="auto">At the moment, there doesn't seem to be a way to do this in one query.</p>
<p dir="auto">Given documents like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&quot;user&quot;: user1,
&quot;credit&quot;: 50"><pre class="notranslate"><code class="notranslate">"user": user1,
"credit": 50
</code></pre></div>
<p dir="auto">we can answer questions such as "Show me only the users that have transactions totalling more than 100" by using a <code class="notranslate">bucket_selector</code> like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&quot;aggs&quot;: {
  &quot;users&quot;: {
    &quot;terms&quot;: {
      &quot;field&quot;: &quot;user&quot;
    },
    &quot;aggs&quot;: {
      &quot;sum_credit&quot;: {
        &quot;sum&quot;: {
          &quot;field&quot;: &quot;credit&quot;
        }
      },
      &quot;the_pipeline_agg&quot;: {
        &quot;bucket_selector&quot;: {
          &quot;buckets_path&quot;: {
            &quot;sumCredit&quot;: &quot;sum_credit&quot;
          },
          &quot;script&quot;: &quot;sumCredit &gt; 100&quot;
        }
      }
    }
  }
}"><pre class="notranslate"><code class="notranslate">"aggs": {
  "users": {
    "terms": {
      "field": "user"
    },
    "aggs": {
      "sum_credit": {
        "sum": {
          "field": "credit"
        }
      },
      "the_pipeline_agg": {
        "bucket_selector": {
          "buckets_path": {
            "sumCredit": "sum_credit"
          },
          "script": "sumCredit &gt; 100"
        }
      }
    }
  }
}
</code></pre></div>
<p dir="auto">And now we could form ranges on the client side by running several of these queries in parallel.</p>
<p dir="auto">But to answer the original question we would need some form of range pipeline aggregation like:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&quot;bucket_range&quot;: {
  &quot;buckets_path&quot;: {
    &quot;sumCredit&quot;: &quot;sum_credit&quot;
  },
  &quot;ranges&quot;: [
    { &quot;to&quot;: 100 },
    { &quot;from&quot;: 100, &quot;to&quot;: 200 }
  ]
}"><pre class="notranslate"><code class="notranslate">"bucket_range": {
  "buckets_path": {
    "sumCredit": "sum_credit"
  },
  "ranges": [
    { "to": 100 },
    { "from": 100, "to": 200 }
  ]
}
</code></pre></div>
<p dir="auto">Or maybe even a more generic "bucket defining" pipeline agg, e.g.:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&quot;bucket_definer&quot;: {
  &quot;buckets_path&quot;: {
    &quot;sumCredit&quot;: &quot;sum_credit&quot;
  },
  &quot;bucket_script&quot;: &quot;floor(sumCredit / 100)&quot;
}"><pre class="notranslate"><code class="notranslate">"bucket_definer": {
  "buckets_path": {
    "sumCredit": "sum_credit"
  },
  "bucket_script": "floor(sumCredit / 100)"
}
</code></pre></div>
<p dir="auto">This would define automatically define buckets for 0-100, 100-200, and so on.</p>