arelastic 3.1.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0984b722326d3ec3a60b11114a249eba54399ba4a28a5f05635ec3c6570b16dc'
|
4
|
+
data.tar.gz: 7f4451aa328ab073bc7aa66818bcb98b28ac6d2354c8d086213fdad1a441532d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01d68d3d7669ab860e232fdb6723b70460ddb103e2c8a4b3d4597a49d090b24da4ef25f3a6a847ee76e459e00b8b6f983499216aa9aa672bef80fe0141913af1
|
7
|
+
data.tar.gz: 1a866d2a4b7129a7b59c44ed7c030748937f70bd0539afe9ed45fb6e10ca6a672d1fa4795672b5b9569b34c327764a8a1c798572e49090ebd017a631370430e9
|
@@ -1,22 +1,8 @@
|
|
1
1
|
module Arelastic
|
2
2
|
module Aggregations
|
3
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
4
|
def as_elastic_aggregation
|
14
|
-
{
|
15
|
-
'bucket_selector' => {
|
16
|
-
'buckets_path' => script_params,
|
17
|
-
'script' => script
|
18
|
-
}
|
19
|
-
}
|
5
|
+
{ 'bucket_selector' => options }
|
20
6
|
end
|
21
7
|
end
|
22
8
|
end
|
@@ -1,37 +1,18 @@
|
|
1
1
|
module Arelastic
|
2
2
|
module Aggregations
|
3
3
|
class BucketSort < Arelastic::Aggregations::Aggregation
|
4
|
-
attr_accessor :
|
4
|
+
attr_accessor :sort
|
5
5
|
|
6
6
|
def initialize(name, options = {})
|
7
|
-
|
8
|
-
@from = read_option! options, 'from'
|
9
|
-
@size = read_option! options, 'size'
|
7
|
+
super
|
10
8
|
@sort = read_option! options, 'sort'
|
11
|
-
super(name, options)
|
12
9
|
end
|
13
10
|
|
14
11
|
def as_elastic_aggregation
|
15
|
-
|
16
|
-
|
17
|
-
bucket_sort
|
18
|
-
bucket_sort['size'] = size if size
|
19
|
-
{ 'bucket_sort' => bucket_sort }
|
12
|
+
params = options
|
13
|
+
params = params.merge('sort' => convert_to_elastic(sort)) if sort
|
14
|
+
{ 'bucket_sort' => params }
|
20
15
|
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
16
|
end
|
36
17
|
end
|
37
18
|
end
|
@@ -1,22 +1,22 @@
|
|
1
|
-
require
|
1
|
+
require "helper"
|
2
2
|
|
3
3
|
class Arelastic::Aggregations::BucketSelectorTest < Minitest::Test
|
4
4
|
def test_as_elastic
|
5
|
-
aggregation = Arelastic::Aggregations::BucketSelector.new(
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
aggregation = Arelastic::Aggregations::BucketSelector.new("foo_agg",
|
6
|
+
"buckets_path" => {
|
7
|
+
"foo_bucket" => "foo_bucket_path",
|
8
|
+
"bar_bucket" => "bar_bucket_path"
|
9
9
|
},
|
10
|
-
script
|
10
|
+
"script" => "params.foo_bucket > 10 && params.bar_bucket < 100"
|
11
11
|
)
|
12
12
|
expected = {
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
"foo_agg" => {
|
14
|
+
"bucket_selector" => {
|
15
|
+
"buckets_path" => {
|
16
|
+
"foo_bucket" => "foo_bucket_path",
|
17
|
+
"bar_bucket" => "bar_bucket_path"
|
18
18
|
},
|
19
|
-
|
19
|
+
"script" => "params.foo_bucket > 10 && params.bar_bucket < 100"
|
20
20
|
}
|
21
21
|
}
|
22
22
|
}
|
@@ -1,25 +1,45 @@
|
|
1
|
-
require
|
1
|
+
require "helper"
|
2
2
|
|
3
3
|
class Arelastic::Aggregations::BucketSortTest < Minitest::Test
|
4
|
-
def
|
5
|
-
|
6
|
-
|
4
|
+
def test_as_elastic
|
5
|
+
aggregation = Arelastic::Aggregations::BucketSort.new("foo_agg", "size" => 3, "from" => 5, "sort" => "price")
|
6
|
+
|
7
|
+
expected = {
|
8
|
+
"foo_agg" => {
|
9
|
+
"bucket_sort" => {
|
10
|
+
"sort" => "price",
|
11
|
+
"from" => 5,
|
12
|
+
"size" => 3
|
13
|
+
}
|
14
|
+
}
|
15
|
+
}
|
16
|
+
assert_equal expected, aggregation.as_elastic
|
7
17
|
end
|
8
18
|
|
9
|
-
def
|
10
|
-
|
19
|
+
def test_arelastic_sort
|
20
|
+
sort = Arelastic::Sorts::Field.new("price" => "desc")
|
21
|
+
aggregation = Arelastic::Aggregations::BucketSort.new("foo_agg", "sort" => sort)
|
22
|
+
|
11
23
|
expected = {
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
'size' => 3
|
24
|
+
"foo_agg" => {
|
25
|
+
"bucket_sort" => {
|
26
|
+
"sort" => {"price" => "desc"}
|
16
27
|
}
|
17
28
|
}
|
18
29
|
}
|
19
30
|
assert_equal expected, aggregation.as_elastic
|
20
31
|
end
|
21
32
|
|
22
|
-
def
|
23
|
-
Arelastic::Aggregations::BucketSort.new(
|
33
|
+
def test_optional_sort
|
34
|
+
aggregation = Arelastic::Aggregations::BucketSort.new("foo_agg", "size" => 3)
|
35
|
+
|
36
|
+
expected = {
|
37
|
+
"foo_agg" => {
|
38
|
+
"bucket_sort" => {
|
39
|
+
"size" => 3
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
assert_equal expected, aggregation.as_elastic
|
24
44
|
end
|
25
45
|
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.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Higgins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
11
|
+
date: 2021-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Build Elastic Search queries with objects
|
14
14
|
email: developer@matthewhiggins.com
|