Skip to content

Commit 7fb935e

Browse files
sendkarmi
authored andcommitted
[DSL] Added the pipeline aggregations
This patch adds the support for pipeline aggregations to the Ruby DSL. See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline.html Closes #312
1 parent 1fd5ac1 commit 7fb935e

26 files changed

+957
-0
lines changed
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module Elasticsearch
2+
module DSL
3+
module Search
4+
module Aggregations
5+
6+
# A sibling pipeline aggregation which calculates the (mean) average value of a specified metric in a sibling aggregation.
7+
#
8+
# @example Passing the options as a Hash
9+
#
10+
# aggregation :avg_monthly_sales do
11+
# avg_bucket buckets_path: 'sales_per_month>sales'
12+
# end
13+
#
14+
# @example Passing the options as a block
15+
#
16+
# aggregation :avg_monthly_sales do
17+
# avg_bucket do
18+
# buckets_path 'sales_per_month>sales'
19+
# end
20+
# end
21+
#
22+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-avg-bucket-aggregation.html
23+
#
24+
class AvgBucket
25+
include BaseAggregationComponent
26+
27+
option_method :buckets_path
28+
option_method :gap_policy
29+
option_method :format
30+
end
31+
end
32+
end
33+
end
34+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
module Elasticsearch
2+
module DSL
3+
module Search
4+
module Aggregations
5+
6+
# A parent pipeline aggregation which executes a script which can perform per bucket computations on specified metrics in the parent multi-bucket aggregation.
7+
#
8+
# @example Passing the options as a Hash
9+
#
10+
# aggregation :t-shirt-percentage do
11+
# bucket_script buckets_path: { tShirtSales: 't-shirts>sales', totalSales: 'total_sales' }, script: 'tShirtSales / totalSales * 100'
12+
# end
13+
#
14+
# @example Passing the options as a block
15+
#
16+
# aggregation :t-shirt-percentage do
17+
# bucket_script do
18+
# buckets_path tShirtSales: 't-shirts>sales', totalSales: 'total_sales'
19+
# script 'tShirtSales / totalSales * 100'
20+
# end
21+
# end
22+
#
23+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-script-aggregation.html
24+
#
25+
class BucketScript
26+
include BaseAggregationComponent
27+
28+
option_method :buckets_path
29+
option_method :script
30+
option_method :gap_policy
31+
option_method :format
32+
end
33+
end
34+
end
35+
end
36+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module Elasticsearch
2+
module DSL
3+
module Search
4+
module Aggregations
5+
6+
# A parent pipeline aggregation which executes a script which determines whether the current bucket will be retained in the parent multi-bucket aggregation.
7+
#
8+
# @example Passing the options as a Hash
9+
#
10+
# aggregation :sales_bucket_filter do
11+
# bucket_selector buckets_path: { totalSales: 'total_sales' }, script: 'totalSales <= 50'
12+
# end
13+
#
14+
# @example Passing the options as a block
15+
#
16+
# aggregation :sales_bucket_filter do
17+
# bucket_selector do
18+
# buckets_path totalSales: 'total_sales'
19+
# script 'totalSales <= 50'
20+
# end
21+
# end
22+
#
23+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-selector-aggregation.html
24+
#
25+
class BucketSelector
26+
include BaseAggregationComponent
27+
28+
option_method :buckets_path
29+
option_method :script
30+
option_method :gap_policy
31+
end
32+
end
33+
end
34+
end
35+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module Elasticsearch
2+
module DSL
3+
module Search
4+
module Aggregations
5+
6+
# A parent pipeline aggregation which calculates the cumulative sum of a specified metric in a parent histogram (or date_histogram) aggregation.
7+
#
8+
# @example Passing the options as a Hash
9+
#
10+
# aggregation :cumulative_sales do
11+
# cumulative_sum buckets_path: 'sales'
12+
# end
13+
#
14+
# @example Passing the options as a block
15+
#
16+
# aggregation :cumulative_sales do
17+
# cumulative_sum do
18+
# buckets_path 'sales'
19+
# end
20+
# end
21+
#
22+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-cumulative-sum-aggregation.html
23+
#
24+
class CumulativeSum
25+
include BaseAggregationComponent
26+
27+
option_method :buckets_path
28+
option_method :format
29+
end
30+
end
31+
end
32+
end
33+
end
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module Elasticsearch
2+
module DSL
3+
module Search
4+
module Aggregations
5+
6+
# A parent pipeline aggregation which calculates the derivative of a specified metric in a parent histogram (or date_histogram) aggregation.
7+
#
8+
# @example Passing the options as a Hash
9+
#
10+
# aggregation :sales_deriv do
11+
# derivative buckets_path: 'sales'
12+
# end
13+
#
14+
# @example Passing the options as a block
15+
#
16+
# aggregation :sales_deriv do
17+
# derivative do
18+
# buckets_path 'sales'
19+
# end
20+
# end
21+
#
22+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-derivative-aggregation.html
23+
#
24+
class Derivative
25+
include BaseAggregationComponent
26+
27+
option_method :buckets_path
28+
option_method :gap_policy
29+
option_method :format
30+
end
31+
end
32+
end
33+
end
34+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module Elasticsearch
2+
module DSL
3+
module Search
4+
module Aggregations
5+
6+
# A sibling pipeline aggregation which calculates a variety of stats across all bucket of a specified metric in a sibling aggregation. The specified metric must be numeric and the sibling aggregation must be a multi-bucket aggregation.
7+
#
8+
# @example Passing the options as a Hash
9+
#
10+
# aggregation :stats_monthly_sales do
11+
# extended_stats_bucket buckets_path: 'sales_per_month>sales'
12+
# end
13+
#
14+
# @example Passing the options as a block
15+
#
16+
# aggregation :stats_monthly_sales do
17+
# extended_stats_bucket do
18+
# buckets_path 'sales_per_month>sales'
19+
# end
20+
# end
21+
#
22+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-extended-stats-bucket-aggregation.html
23+
#
24+
class ExtendedStatsBucket
25+
include BaseAggregationComponent
26+
27+
option_method :buckets_path
28+
option_method :gap_policy
29+
option_method :format
30+
end
31+
end
32+
end
33+
end
34+
end
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module Elasticsearch
2+
module DSL
3+
module Search
4+
module Aggregations
5+
6+
# A sibling pipeline aggregation which identifies the bucket(s) with the maximum value of a specified metric in a sibling aggregation and outputs both the value and the key(s) of the bucket(s).
7+
#
8+
# @example Passing the options as a Hash
9+
#
10+
# aggregation :max_monthly_sales do
11+
# max_bucket buckets_path: 'sales_per_month>sales'
12+
# end
13+
#
14+
# @example Passing the options as a block
15+
#
16+
# aggregation :max_monthly_sales do
17+
# max_bucket do
18+
# buckets_path 'sales_per_month>sales'
19+
# end
20+
# end
21+
#
22+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-max-bucket-aggregation.html
23+
#
24+
class MaxBucket
25+
include BaseAggregationComponent
26+
27+
option_method :buckets_path
28+
option_method :gap_policy
29+
option_method :format
30+
end
31+
end
32+
end
33+
end
34+
end
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module Elasticsearch
2+
module DSL
3+
module Search
4+
module Aggregations
5+
6+
# A sibling pipeline aggregation which identifies the bucket(s) with the minimum value of a specified metric in a sibling aggregation and outputs both the value and the key(s) of the bucket(s).
7+
#
8+
# @example Passing the options as a Hash
9+
#
10+
# aggregation :min_monthly_sales do
11+
# min_bucket buckets_path: 'sales_per_month>sales'
12+
# end
13+
#
14+
# @example Passing the options as a block
15+
#
16+
# aggregation :min_monthly_sales do
17+
# min_bucket do
18+
# buckets_path 'sales_per_month>sales'
19+
# end
20+
# end
21+
#
22+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-min-bucket-aggregation.html
23+
#
24+
class MinBucket
25+
include BaseAggregationComponent
26+
27+
option_method :buckets_path
28+
option_method :gap_policy
29+
option_method :format
30+
end
31+
end
32+
end
33+
end
34+
end
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
module Elasticsearch
2+
module DSL
3+
module Search
4+
module Aggregations
5+
6+
# Given an ordered series of data, the Moving Average aggregation will slide a window across the data and emit the average value of that window.
7+
#
8+
# @example Passing the options as a Hash
9+
#
10+
# aggregation :the_movavg do
11+
# moving_avg buckets_path: 'the_sum'
12+
# end
13+
#
14+
# @example Passing the options as a block
15+
#
16+
# aggregation :the_movavg do
17+
# moving_avg do
18+
# buckets_path 'the_sum'
19+
# model 'holt'
20+
# window 5
21+
# gap_policy 'insert_zero'
22+
# settings({ alpha: 0.5 })
23+
# end
24+
# end
25+
#
26+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-movavg-aggregation.html
27+
#
28+
class MovingAvg
29+
include BaseAggregationComponent
30+
31+
option_method :buckets_path
32+
option_method :model
33+
option_method :gap_policy
34+
option_method :window
35+
option_method :format
36+
option_method :minimize
37+
option_method :settings
38+
end
39+
end
40+
end
41+
end
42+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
module Elasticsearch
2+
module DSL
3+
module Search
4+
module Aggregations
5+
6+
# A sibling pipeline aggregation which calculates percentiles across all bucket of a specified metric in a sibling aggregation.
7+
#
8+
# @example Passing the options as a Hash
9+
#
10+
# aggregation :sum_monthly_sales do
11+
# percentiles_bucket buckets_path: 'sales_per_month>sales'
12+
# end
13+
#
14+
# @example Passing the options as a block
15+
#
16+
# aggregation :sum_monthly_sales do
17+
# percentiles_bucket do
18+
# buckets_path 'sales_per_month>sales'
19+
# percents [25.0 50.0 75.0]
20+
# end
21+
# end
22+
#
23+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-percentiles-bucket-aggregation.html
24+
#
25+
class PercentilesBucket
26+
include BaseAggregationComponent
27+
28+
option_method :buckets_path
29+
option_method :gap_policy
30+
option_method :format
31+
option_method :percents
32+
end
33+
end
34+
end
35+
end
36+
end
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
module Elasticsearch
2+
module DSL
3+
module Search
4+
module Aggregations
5+
6+
# Serial differencing is a technique where values in a time series are subtracted from itself at different time lags or periods.
7+
#
8+
# @example Passing the options as a Hash
9+
#
10+
# aggregation :thirtieth_difference do
11+
# serial_diff buckets_path: 'the_sum'
12+
# end
13+
#
14+
# @example Passing the options as a block
15+
#
16+
# aggregation :thirtieth_difference do
17+
# serial_diff do
18+
# buckets_path 'the_sum'
19+
# lag 30
20+
# end
21+
# end
22+
#
23+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-serialdiff-aggregation.html
24+
#
25+
class SerialDiff
26+
include BaseAggregationComponent
27+
28+
option_method :buckets_path
29+
option_method :lag
30+
option_method :gap_policy
31+
option_method :format
32+
end
33+
end
34+
end
35+
end
36+
end

0 commit comments

Comments
 (0)