arelastic 3.0.0 → 3.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 41849e76c34d20f19af86422794c1c7c5245d8355cb6a453decc6c87934dbb66
4
- data.tar.gz: a32b6ef72a9a28bccba585a0f93e04586a42b18f2ec23bb79134c59a618ea2d0
3
+ metadata.gz: b92131dd2729b5be9ad302a31d33db3482ecc47dee0b97681b3cca050cf627ba
4
+ data.tar.gz: d2c3fa9dc8ffe7c8f1c268c030964f23281b15dcba1655bc845d6c5ce8a91862
5
5
  SHA512:
6
- metadata.gz: c109a5bd0a2a6e10aa9e9da405574d86b9d0e74795fd61101b0966aab00c57c41043043b268c94f004127f78b5bc6e6f45116fa1f8ca8f962e41ebeb3ff31d43
7
- data.tar.gz: 1f5da97d3217067aac0963b059dff48083da71c02d116b8d3e7a3e4ead1c9786833c5218b84a69fb96b4858447417e5c252aa965ad3bd08925f821493931a8c8
6
+ metadata.gz: 3e1e3bbdb544e0ee9b39b8c48100339e4340a0adf5985c5a524187ca7758798f596fdf2f7fb3ed221a5334f9f882e037d740267fa29a5cd434c3c13c015fdc3c
7
+ data.tar.gz: 7e3578aa3af4ca0efb60fe148a0cd611144d76c9e18b5a78623f43778b3b792e5987a8745dde2e175002e50a4781227bf86500f72716efab76b26387392a4337
@@ -1,6 +1,8 @@
1
1
  require 'arelastic/aggregations/aggregation'
2
2
  require 'arelastic/aggregations/bucket'
3
3
 
4
+ require 'arelastic/aggregations/bucket_sort'
5
+ require 'arelastic/aggregations/bucket_selector'
4
6
  require 'arelastic/aggregations/cardinality'
5
7
  require 'arelastic/aggregations/date_histogram'
6
8
  require 'arelastic/aggregations/filter'
@@ -0,0 +1,23 @@
1
+ module Arelastic
2
+ module Aggregations
3
+ class BucketSelector < Arelastic::Aggregations::Aggregation
4
+ attr_accessor :script_params, :script
5
+
6
+ def initialize(name, options = {})
7
+ options = options.dup
8
+ @script_params = read_option! options, 'script_params'
9
+ @script = read_option! options, 'script'
10
+ super(name, options)
11
+ end
12
+
13
+ def as_elastic_aggregation
14
+ {
15
+ 'bucket_selector' => {
16
+ 'buckets_path' => script_params,
17
+ 'script' => script
18
+ }
19
+ }
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,37 @@
1
+ module Arelastic
2
+ module Aggregations
3
+ class BucketSort < Arelastic::Aggregations::Aggregation
4
+ attr_accessor :from, :size, :sort
5
+
6
+ def initialize(name, options = {})
7
+ options = options.dup
8
+ @from = read_option! options, 'from'
9
+ @size = read_option! options, 'size'
10
+ @sort = read_option! options, 'sort'
11
+ super(name, options)
12
+ end
13
+
14
+ def as_elastic_aggregation
15
+ bucket_sort = {}
16
+ bucket_sort['sort'] = parse_sort if sort
17
+ bucket_sort['from'] = from if from
18
+ bucket_sort['size'] = size if size
19
+ { 'bucket_sort' => bucket_sort }
20
+ end
21
+
22
+ private
23
+
24
+ def parse_sort
25
+ if sort.is_a?(Hash)
26
+ sort.map { |bucket_path, order| { bucket_path => order } }
27
+ elsif sort.is_a?(String)
28
+ [sort]
29
+ elsif sort.is_a?(Array)
30
+ sort
31
+ else
32
+ raise TypeError.new('Expecting a hash, string, or array as the "sort" argument')
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,25 @@
1
+ require 'helper'
2
+
3
+ class Arelastic::Aggregations::BucketSelectorTest < Minitest::Test
4
+ def test_as_elastic
5
+ aggregation = Arelastic::Aggregations::BucketSelector.new('foo_agg',
6
+ script_params: {
7
+ 'foo_bucket' => 'foo_bucket_path',
8
+ 'bar_bucket' => 'bar_bucket_path'
9
+ },
10
+ script: "params.foo_bucket > 10 && params.bar_bucket < 100"
11
+ )
12
+ expected = {
13
+ 'foo_agg' => {
14
+ 'bucket_selector' => {
15
+ 'buckets_path' => {
16
+ 'foo_bucket' => 'foo_bucket_path',
17
+ 'bar_bucket' => 'bar_bucket_path'
18
+ },
19
+ 'script' => 'params.foo_bucket > 10 && params.bar_bucket < 100'
20
+ }
21
+ }
22
+ }
23
+ assert_equal expected, aggregation.as_elastic
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require 'helper'
2
+
3
+ class Arelastic::Aggregations::BucketSortTest < Minitest::Test
4
+ def test_parse_sort
5
+ assert_equal ['foo'], parse_sort('foo')
6
+ assert_equal [{'foo' => 'desc'}, {'bar' => 'asc'}], parse_sort({'foo' => 'desc', 'bar' => 'asc'})
7
+ end
8
+
9
+ def test_size_and_from
10
+ aggregation = Arelastic::Aggregations::BucketSort.new('foo_agg', 'size' => 3, 'from' => 5)
11
+ expected = {
12
+ 'foo_agg' => {
13
+ 'bucket_sort' => {
14
+ 'from' => 5,
15
+ 'size' => 3
16
+ }
17
+ }
18
+ }
19
+ assert_equal expected, aggregation.as_elastic
20
+ end
21
+
22
+ def parse_sort(sort)
23
+ Arelastic::Aggregations::BucketSort.new('foosort', sort: sort).as_elastic['foosort']['bucket_sort']['sort']
24
+ end
25
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arelastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Higgins
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-23 00:00:00.000000000 Z
11
+ date: 2021-05-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Build Elastic Search queries with objects
14
14
  email: developer@matthewhiggins.com
@@ -22,6 +22,8 @@ files:
22
22
  - lib/arelastic/aggregations.rb
23
23
  - lib/arelastic/aggregations/aggregation.rb
24
24
  - lib/arelastic/aggregations/bucket.rb
25
+ - lib/arelastic/aggregations/bucket_selector.rb
26
+ - lib/arelastic/aggregations/bucket_sort.rb
25
27
  - lib/arelastic/aggregations/cardinality.rb
26
28
  - lib/arelastic/aggregations/date_histogram.rb
27
29
  - lib/arelastic/aggregations/filter.rb
@@ -101,6 +103,8 @@ files:
101
103
  - lib/arelastic/sorts/geo_distance.rb
102
104
  - lib/arelastic/sorts/sort.rb
103
105
  - test/arelastic/aggregations/aggregation_test.rb
106
+ - test/arelastic/aggregations/bucket_selector_test.rb
107
+ - test/arelastic/aggregations/bucket_sort_test.rb
104
108
  - test/arelastic/aggregations/bucket_test.rb
105
109
  - test/arelastic/aggregations/cardinality_test.rb
106
110
  - test/arelastic/aggregations/date_histogram_test.rb
@@ -156,7 +160,7 @@ homepage: http://github.com/matthuhiggins/arelastic
156
160
  licenses:
157
161
  - MIT
158
162
  metadata: {}
159
- post_install_message:
163
+ post_install_message:
160
164
  rdoc_options: []
161
165
  require_paths:
162
166
  - lib
@@ -171,8 +175,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
175
  - !ruby/object:Gem::Version
172
176
  version: '0'
173
177
  requirements: []
174
- rubygems_version: 3.0.3
175
- signing_key:
178
+ rubygems_version: 3.2.15
179
+ signing_key:
176
180
  specification_version: 4
177
181
  summary: Elastic Search query builder
178
182
  test_files: []