elasticsearch-dsl 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -3
- data/elasticsearch-dsl.gemspec +5 -1
- data/lib/elasticsearch/dsl/search.rb +1 -1
- data/lib/elasticsearch/dsl/search/aggregations/missing.rb +36 -0
- data/lib/elasticsearch/dsl/search/aggregations/pipeline/avg_bucket.rb +34 -0
- data/lib/elasticsearch/dsl/search/aggregations/pipeline/bucket_script.rb +36 -0
- data/lib/elasticsearch/dsl/search/aggregations/pipeline/bucket_selector.rb +35 -0
- data/lib/elasticsearch/dsl/search/aggregations/pipeline/cumulative_sum.rb +33 -0
- data/lib/elasticsearch/dsl/search/aggregations/pipeline/derivative.rb +34 -0
- data/lib/elasticsearch/dsl/search/aggregations/pipeline/extended_stats_bucket.rb +34 -0
- data/lib/elasticsearch/dsl/search/aggregations/pipeline/max_bucket.rb +34 -0
- data/lib/elasticsearch/dsl/search/aggregations/pipeline/min_bucket.rb +34 -0
- data/lib/elasticsearch/dsl/search/aggregations/pipeline/moving_avg.rb +42 -0
- data/lib/elasticsearch/dsl/search/aggregations/pipeline/percentiles_bucket.rb +36 -0
- data/lib/elasticsearch/dsl/search/aggregations/pipeline/serial_diff.rb +36 -0
- data/lib/elasticsearch/dsl/search/aggregations/pipeline/stats_bucket.rb +34 -0
- data/lib/elasticsearch/dsl/search/aggregations/pipeline/sum_bucket.rb +34 -0
- data/lib/elasticsearch/dsl/search/queries/bool.rb +10 -0
- data/lib/elasticsearch/dsl/search/sort.rb +11 -2
- data/lib/elasticsearch/dsl/version.rb +1 -1
- data/test/integration/search_test.rb +60 -0
- data/test/unit/aggregations/missing_test.rb +39 -0
- data/test/unit/aggregations/pipeline/avg_bucket_test.rb +39 -0
- data/test/unit/aggregations/pipeline/bucket_script_test.rb +39 -0
- data/test/unit/aggregations/pipeline/bucket_selector_test.rb +38 -0
- data/test/unit/aggregations/pipeline/cumulative_sum_test.rb +37 -0
- data/test/unit/aggregations/pipeline/derivative_test.rb +39 -0
- data/test/unit/aggregations/pipeline/extended_stats_bucket_test.rb +38 -0
- data/test/unit/aggregations/pipeline/max_bucket_test.rb +38 -0
- data/test/unit/aggregations/pipeline/min_bucket_test.rb +38 -0
- data/test/unit/aggregations/pipeline/moving_avg_test.rb +41 -0
- data/test/unit/aggregations/pipeline/percentiles_bucket_test.rb +39 -0
- data/test/unit/aggregations/pipeline/serial_diff_test.rb +39 -0
- data/test/unit/aggregations/pipeline/stats_bucket_test.rb +38 -0
- data/test/unit/aggregations/pipeline/sum_bucket_test.rb +38 -0
- data/test/unit/queries/bool_test.rb +9 -0
- data/test/unit/search_sort_test.rb +25 -0
- data/test/unit/search_test.rb +34 -0
- metadata +50 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e9bb408fa97be4d12b615340b7fa44090287e08
|
4
|
+
data.tar.gz: d4c70bf0fcc2864c11226855c471dc921d23687c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0cdfe1bfb6786cffd3610c4fd9687fb86baf6b51c49d0282d867ebb4cf91fbd0aaa1c0594a572e01ad0ca34a2ce5fc56feff1761a319943fead579a1f4d1628
|
7
|
+
data.tar.gz: d721ec3d8824fff4598984d0292c07df508134d431264fe51a54404dec837e45de2d7ccb2fa4a6c07faf5000ee4842693ed80e344fb59118566c4b4895cae115
|
data/README.md
CHANGED
@@ -110,9 +110,11 @@ All Elasticsearch DSL features are supported, namely:
|
|
110
110
|
|
111
111
|
An example of a complex search definition is below.
|
112
112
|
|
113
|
-
**NOTE:** In order to run the example, you have to allow restoring from the `data.elasticsearch.org`
|
114
|
-
|
115
|
-
|
113
|
+
**NOTE:** In order to run the example, you have to allow restoring from the `data.elasticsearch.org` repository by adding the following configuration line to your `elasticsearch.yml`:
|
114
|
+
|
115
|
+
```yaml
|
116
|
+
repositories.url.allowed_urls: ["https://s3.amazonaws.com/data.elasticsearch.org/*"]
|
117
|
+
```
|
116
118
|
|
117
119
|
```ruby
|
118
120
|
require 'awesome_print'
|
data/elasticsearch-dsl.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.rdoc_options = [ "--charset=UTF-8" ]
|
23
23
|
|
24
24
|
s.add_development_dependency "bundler", "~> 1.3"
|
25
|
-
s.add_development_dependency "rake"
|
25
|
+
s.add_development_dependency "rake", "~> 11.1"
|
26
26
|
|
27
27
|
s.add_development_dependency "elasticsearch"
|
28
28
|
s.add_development_dependency "elasticsearch-extensions"
|
@@ -37,4 +37,8 @@ Gem::Specification.new do |s|
|
|
37
37
|
s.add_development_dependency 'yard'
|
38
38
|
s.add_development_dependency 'cane'
|
39
39
|
s.add_development_dependency 'pry'
|
40
|
+
|
41
|
+
if defined?(RUBY_VERSION) && RUBY_VERSION > '2.2'
|
42
|
+
s.add_development_dependency "test-unit", '~> 2'
|
43
|
+
end
|
40
44
|
end
|
@@ -39,7 +39,7 @@ module Elasticsearch
|
|
39
39
|
|
40
40
|
def initialize(*args, &block)
|
41
41
|
@options = Options.new *args
|
42
|
-
instance_eval(&block) if block
|
42
|
+
block.arity < 1 ? self.instance_eval(&block) : block.call(self) if block
|
43
43
|
end
|
44
44
|
|
45
45
|
# DSL method for building or accessing the `query` part of a search definition
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Elasticsearch
|
2
|
+
module DSL
|
3
|
+
module Search
|
4
|
+
module Aggregations
|
5
|
+
|
6
|
+
# A single bucket aggregation that creates a bucket of all documents
|
7
|
+
# which are missing a value for the field
|
8
|
+
#
|
9
|
+
# @example Passing the options as a Hash
|
10
|
+
#
|
11
|
+
# aggregation :articles_without_tags do
|
12
|
+
# missing field: 'tags'
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# @example Passing the options as a block
|
16
|
+
#
|
17
|
+
# search do
|
18
|
+
# aggregation :articles_without_tags do
|
19
|
+
# missing do
|
20
|
+
# field 'tags'
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/master/search-aggregations-bucket-missing-aggregation.html
|
26
|
+
#
|
27
|
+
class Missing
|
28
|
+
include BaseAggregationComponent
|
29
|
+
|
30
|
+
option_method :field
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -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
|
@@ -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
|
@@ -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
|
@@ -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
|
@@ -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
|
@@ -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
|
@@ -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
|
@@ -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
|
@@ -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
|
@@ -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
|