Add bucket_selector pipeline aggregation support to QueryBuilder#50
Closed
Add bucket_selector pipeline aggregation support to QueryBuilder#50
Conversation
…ilder This change adds support for Elasticsearch's `bucket_selector` pipeline aggregation to the QueryBuilder DSL. The new aggregation allows filtering buckets based on computed metrics (e.g. retaining only those buckets where a sum or average exceeds a threshold), a capability not previously exposed through the DSL.
e8f27b9 to
469719e
Compare
sergio-bobillier
requested changes
Jan 19, 2026
| attr_reader :buckets_path, :script, :gap_policy | ||
|
|
||
| # @param [String] name The name used by Elasticsearch to identify the aggregation. | ||
| # @param [Hash,String] buckets_path Path(s) to the metrics in parent aggs. |
Collaborator
There was a problem hiding this comment.
Missing space after the comma:
Suggested change
| # @param [Hash,String] buckets_path Path(s) to the metrics in parent aggs. | |
| # @param [Hash, String] buckets_path Path(s) to the metrics in parent aggs. |
| self.class.new( | ||
| name, | ||
| buckets_path: buckets_path.is_a?(Hash) ? buckets_path.dup : buckets_path, | ||
| script: script, # Script is immutable-ish, ok to reuse |
Collaborator
There was a problem hiding this comment.
Please take care of the linter warning on this line.
|
|
||
| let(:name) { 'only_slow_tests' } | ||
| let(:buckets_path) { { total: 'total_duration_ms' } } | ||
| let(:script) do |
Collaborator
There was a problem hiding this comment.
Nit: Please add an empty line between lines 519 and 520
| JayAPI::Elasticsearch::QueryBuilder::Script | ||
| ) | ||
| end | ||
| let(:gap_policy) { nil } |
Collaborator
There was a problem hiding this comment.
Nit: Please add an empty line between lines 524 and 525
|
|
||
| it 'creates the BucketSelector instance with the expected parameters' do | ||
| expect(JayAPI::Elasticsearch::QueryBuilder::Aggregations::BucketSelector) | ||
| .to receive(:new).with( |
Collaborator
There was a problem hiding this comment.
Please reformat this to avoid the RSpec/ExampleLength linter warning:
Suggested change
| .to receive(:new).with( | |
| .to receive(:new).with(name, buckets_path: buckets_path, script: script, gap_policy: gap_policy) |
|
|
||
| it 'creates the BucketSelector instance with the expected parameters' do | ||
| expect(JayAPI::Elasticsearch::QueryBuilder::Aggregations::BucketSelector) | ||
| .to receive(:new).with( |
Collaborator
There was a problem hiding this comment.
Likewise here, please reflow the code to avoid the linter warning.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add support for the bucket_selector pipeline aggregation to the QueryBuilder DSL. This allows filtering buckets based on computed metrics.
Example use case: group test executions by test name, compute total duration per test, and keep only tests that exceed a minimum total duration.
DSL usage:
Generated JSON:
Motivation: the previous DSL had no way to express post-aggregation filtering, forcing either client-side filtering or dropping to raw JSON. This feature enables pipeline filtering directly through the DSL.