arelastic 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/arelastic/aggregations.rb +2 -0
- data/lib/arelastic/aggregations/aggregation.rb +5 -1
- data/lib/arelastic/aggregations/bucket.rb +25 -0
- data/lib/arelastic/aggregations/date_histogram.rb +2 -2
- data/lib/arelastic/aggregations/filter.rb +3 -3
- data/lib/arelastic/aggregations/min.rb +1 -1
- data/lib/arelastic/aggregations/nested.rb +6 -14
- data/lib/arelastic/aggregations/reverse_nested.rb +18 -0
- data/lib/arelastic/aggregations/terms.rb +1 -1
- data/lib/arelastic/builders/aggregation.rb +1 -1
- data/lib/arelastic/nodes/hash_group.rb +2 -4
- data/lib/arelastic/searches/aggregations.rb +5 -8
- data/test/arelastic/aggregations/aggregation_test.rb +9 -14
- data/test/arelastic/aggregations/bucket_test.rb +30 -0
- data/test/arelastic/aggregations/nested_test.rb +19 -2
- data/test/arelastic/aggregations/reverse_nested_test.rb +44 -0
- data/test/arelastic/aggregations/terms_test.rb +1 -1
- data/test/arelastic/filters/filter_test.rb +2 -2
- data/test/arelastic/searches/aggregations_test.rb +1 -23
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d96135e275fd9ab247666893b15e684ee782dead
|
4
|
+
data.tar.gz: cdc3cd878e4c5f71a0f90d9c3337e9b4611e3df3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82a9a205c20da2f7aa6908faa80073c1ed170173580436eac6b92b3e2903bdb88b1fa016cc5d89e3e1f256e979a48cf8e372d41f904cf3f40e698fb117a52c1b
|
7
|
+
data.tar.gz: 93736e6182ddfdfefabf2680e94c2d4e65d9fff3de38d02ce94827758d444d9c8ec56b2d8dd52c40aba5fe1c7af8697eb82f95e55d421ab3eb81946e094b6296
|
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'arelastic/aggregations/aggregation'
|
2
|
+
require 'arelastic/aggregations/bucket'
|
2
3
|
|
3
4
|
require 'arelastic/aggregations/date_histogram'
|
4
5
|
require 'arelastic/aggregations/filter'
|
5
6
|
require 'arelastic/aggregations/min'
|
6
7
|
require 'arelastic/aggregations/nested'
|
8
|
+
require 'arelastic/aggregations/reverse_nested'
|
7
9
|
require 'arelastic/aggregations/terms'
|
@@ -4,7 +4,7 @@ module Arelastic
|
|
4
4
|
attr_accessor :name, :options
|
5
5
|
|
6
6
|
def initialize(name, options = {})
|
7
|
-
@name
|
7
|
+
@name = name
|
8
8
|
@options = options
|
9
9
|
end
|
10
10
|
|
@@ -16,6 +16,10 @@ module Arelastic
|
|
16
16
|
Arelastic::Aggregations::Nested.new(name, path, [self])
|
17
17
|
end
|
18
18
|
|
19
|
+
def reverse_nested(path = nil)
|
20
|
+
Arelastic::Aggregations::ReverseNested.new(name, path, [self])
|
21
|
+
end
|
22
|
+
|
19
23
|
def as_elastic_aggregation
|
20
24
|
raise 'not implemented'
|
21
25
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Arelastic
|
2
|
+
module Aggregations
|
3
|
+
class Bucket < Arelastic::Aggregations::Aggregation
|
4
|
+
attr_accessor :aggs
|
5
|
+
|
6
|
+
def initialize(name, options = {})
|
7
|
+
options = options.dup
|
8
|
+
@aggs = options.delete(:aggs) || options.delete('aggs')
|
9
|
+
super(name, options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def as_elastic
|
13
|
+
{name => as_elastic_aggregation.merge(sub_aggregations_as_elastic)}
|
14
|
+
end
|
15
|
+
|
16
|
+
def sub_aggregations_as_elastic
|
17
|
+
if aggs
|
18
|
+
{'aggs' => Arelastic::Nodes::HashGroup.new(aggs).as_elastic}
|
19
|
+
else
|
20
|
+
{}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module Arelastic
|
2
2
|
module Aggregations
|
3
|
-
class Filter < Arelastic::Aggregations::
|
3
|
+
class Filter < Arelastic::Aggregations::Bucket
|
4
4
|
attr_accessor :filter
|
5
5
|
|
6
|
-
def initialize
|
7
|
-
super name
|
6
|
+
def initialize(name, filter, options = {})
|
7
|
+
super name, options
|
8
8
|
@filter = filter
|
9
9
|
end
|
10
10
|
|
@@ -1,23 +1,15 @@
|
|
1
1
|
module Arelastic
|
2
2
|
module Aggregations
|
3
|
-
class Nested < Arelastic::Aggregations::
|
4
|
-
attr_accessor :path
|
3
|
+
class Nested < Arelastic::Aggregations::Bucket
|
4
|
+
attr_accessor :path
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
super name
|
6
|
+
def initialize(name, path, aggs)
|
7
|
+
super name, aggs: aggs
|
9
8
|
@path = path
|
10
|
-
@aggregations = aggregations
|
11
9
|
end
|
12
10
|
|
13
|
-
def
|
14
|
-
|
15
|
-
{
|
16
|
-
name => {
|
17
|
-
"nested" => {"path" => path},
|
18
|
-
"aggs" => grouping.as_elastic
|
19
|
-
}
|
20
|
-
}
|
11
|
+
def as_elastic_aggregation
|
12
|
+
{ "nested" => { "path" => path } }
|
21
13
|
end
|
22
14
|
end
|
23
15
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Arelastic
|
2
|
+
module Aggregations
|
3
|
+
class ReverseNested < Arelastic::Aggregations::Bucket
|
4
|
+
attr_accessor :path
|
5
|
+
|
6
|
+
def initialize(name, path = nil, aggs)
|
7
|
+
super name, aggs: aggs
|
8
|
+
@path = path
|
9
|
+
end
|
10
|
+
|
11
|
+
def as_elastic_aggregation
|
12
|
+
params = path ? { "path" => path } : {}
|
13
|
+
|
14
|
+
{ "reverse_nested" => params }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,19 +1,16 @@
|
|
1
1
|
module Arelastic
|
2
2
|
module Searches
|
3
3
|
class Aggregations < Arelastic::Searches::Search
|
4
|
-
attr_accessor :
|
5
|
-
|
6
|
-
|
4
|
+
attr_accessor :aggs
|
5
|
+
|
6
|
+
def initialize *aggs
|
7
|
+
@aggs = aggs.flatten
|
7
8
|
end
|
8
9
|
|
9
10
|
def as_elastic
|
10
|
-
grouping = Arelastic::Nodes::HashGroup.new
|
11
|
+
grouping = Arelastic::Nodes::HashGroup.new(aggs)
|
11
12
|
{ "aggs" => grouping.as_elastic }
|
12
13
|
end
|
13
|
-
|
14
|
-
def nested(name, path)
|
15
|
-
Arelastic::Aggregations::Nested.new name, path, aggregations
|
16
|
-
end
|
17
14
|
end
|
18
15
|
end
|
19
16
|
end
|
@@ -4,19 +4,14 @@ class Arelastic::Aggregations::AggregationTest < Minitest::Test
|
|
4
4
|
def test_nested
|
5
5
|
aggregation = Arelastic::Aggregations::Min.new('smallest', 'field' => 'pets.weight').nested('pets')
|
6
6
|
|
7
|
-
expected =
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
"smallest" => {
|
14
|
-
"min" => { "field" => "pets.weight" }
|
15
|
-
}
|
16
|
-
}
|
17
|
-
}
|
18
|
-
}
|
7
|
+
expected = Arelastic::Aggregations::Nested.new('smallest', 'pets', [aggregation])
|
8
|
+
assert_equal expected, aggregation.nested('pets')
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_reverse_nested
|
12
|
+
aggregation = Arelastic::Aggregations::Min.new('smallest', 'field' => 'pets.weight').reverse_nested('pets')
|
19
13
|
|
20
|
-
|
14
|
+
expected = Arelastic::Aggregations::ReverseNested.new('smallest', 'pets', [aggregation])
|
15
|
+
assert_equal expected, aggregation.reverse_nested('pets')
|
21
16
|
end
|
22
|
-
end
|
17
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::Aggregations::BucketTest < Minitest::Test
|
4
|
+
def test_as_elastic_with_sub_aggregations
|
5
|
+
aggregation = Arelastic::Aggregations::Terms.new('foo',
|
6
|
+
'field' => 'tags',
|
7
|
+
'size' => 10,
|
8
|
+
'aggs' => [
|
9
|
+
Arelastic::Aggregations::Terms.new('colors', 'field' => 'color')
|
10
|
+
]
|
11
|
+
)
|
12
|
+
|
13
|
+
expected = {
|
14
|
+
"foo" => {
|
15
|
+
"terms" => {
|
16
|
+
"field" => "tags",
|
17
|
+
"size" => 10,
|
18
|
+
},
|
19
|
+
"aggs" => {
|
20
|
+
"colors" => {
|
21
|
+
"terms" => {
|
22
|
+
"field" => "color"
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
28
|
+
assert_equal expected, aggregation.as_elastic
|
29
|
+
end
|
30
|
+
end
|
@@ -3,7 +3,24 @@ require 'helper'
|
|
3
3
|
class Arelastic::Aggregations::NestedTest < Minitest::Test
|
4
4
|
def test_as_elastic
|
5
5
|
aggregation = Arelastic::Aggregations::Nested.new('favorite', 'movies', [
|
6
|
-
|
6
|
+
Arelastic::Aggregations::Terms.new('foo', 'field' => 'tags', 'size' => 10)
|
7
7
|
])
|
8
|
+
|
9
|
+
expected = {
|
10
|
+
"favorite" => {
|
11
|
+
"nested" => {
|
12
|
+
"path" => "movies"
|
13
|
+
},
|
14
|
+
"aggs" => {
|
15
|
+
"foo" => {
|
16
|
+
"terms" => {
|
17
|
+
"field" => "tags",
|
18
|
+
"size" => 10
|
19
|
+
}
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
24
|
+
assert_equal expected, aggregation.as_elastic
|
8
25
|
end
|
9
|
-
end
|
26
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::Aggregations::ReverseNestedTest < Minitest::Test
|
4
|
+
def test_as_elastic
|
5
|
+
aggregation = Arelastic::Aggregations::ReverseNested.new(
|
6
|
+
'smallest',
|
7
|
+
'pets',
|
8
|
+
[Arelastic::Aggregations::Min.new('smallest', 'field' => 'pets.weight')]
|
9
|
+
)
|
10
|
+
|
11
|
+
expected = {
|
12
|
+
"smallest" => {
|
13
|
+
"reverse_nested" => {
|
14
|
+
"path" => "pets"
|
15
|
+
},
|
16
|
+
"aggs" => {
|
17
|
+
"smallest" => {
|
18
|
+
"min" => { "field" => "pets.weight" }
|
19
|
+
}
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
assert_equal expected, aggregation.as_elastic
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_as_elastic_without_path
|
27
|
+
aggregation = Arelastic::Aggregations::ReverseNested.new(
|
28
|
+
'youngest',
|
29
|
+
[Arelastic::Aggregations::Min.new('youngest', 'field' => 'age')]
|
30
|
+
)
|
31
|
+
|
32
|
+
expected = {
|
33
|
+
"youngest" => {
|
34
|
+
"reverse_nested" => {},
|
35
|
+
"aggs" => {
|
36
|
+
"youngest" => {
|
37
|
+
"min" => { "field" => "age" }
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
assert_equal expected, aggregation.as_elastic
|
43
|
+
end
|
44
|
+
end
|
@@ -3,6 +3,7 @@ require 'helper'
|
|
3
3
|
class Arelastic::Aggregations::TermsTest < Minitest::Test
|
4
4
|
def test_as_elastic
|
5
5
|
aggregation = Arelastic::Aggregations::Terms.new('foo', 'field' => 'tags', 'size' => 10)
|
6
|
+
|
6
7
|
expected = {
|
7
8
|
"foo" => {
|
8
9
|
"terms" => {
|
@@ -11,7 +12,6 @@ class Arelastic::Aggregations::TermsTest < Minitest::Test
|
|
11
12
|
}
|
12
13
|
}
|
13
14
|
}
|
14
|
-
|
15
15
|
assert_equal expected, aggregation.as_elastic
|
16
16
|
end
|
17
17
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class Arelastic::FilterTest < Minitest::Test
|
4
|
-
def
|
4
|
+
def test_and
|
5
5
|
filter = Arelastic::Filters::Filter.new
|
6
6
|
|
7
7
|
and_filter = filter.and(filter)
|
@@ -10,7 +10,7 @@ class Arelastic::FilterTest < Minitest::Test
|
|
10
10
|
assert_equal [filter, filter], and_filter.children
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def test_or
|
14
14
|
filter = Arelastic::Filters::Filter.new
|
15
15
|
|
16
16
|
and_filter = filter.or(filter)
|
@@ -26,26 +26,4 @@ class Arelastic::Searches::AggregationsTest < MiniTest::Spec
|
|
26
26
|
}
|
27
27
|
assert_equal expected, aggregations.as_elastic
|
28
28
|
end
|
29
|
-
|
30
|
-
def test_nested
|
31
|
-
aggregations = Arelastic::Searches::Aggregations.new "favorites" => {"terms" => {"field" => "pencils.color"}}
|
32
|
-
nested = aggregations.nested("pencil_colors", "pencils")
|
33
|
-
|
34
|
-
expected = {
|
35
|
-
"pencil_colors" => {
|
36
|
-
"nested" => {
|
37
|
-
"path" => "pencils"
|
38
|
-
},
|
39
|
-
"aggs" => {
|
40
|
-
"favorites" => {
|
41
|
-
"terms" => {
|
42
|
-
"field"=>"pencils.color"
|
43
|
-
}
|
44
|
-
}
|
45
|
-
}
|
46
|
-
}
|
47
|
-
}
|
48
|
-
|
49
|
-
assert_equal expected, nested.as_elastic
|
50
|
-
end
|
51
|
-
end
|
29
|
+
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: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Higgins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Build Elastic Search queries with objects
|
14
14
|
email: developer@matthewhiggins.com
|
@@ -21,11 +21,13 @@ files:
|
|
21
21
|
- lib/arelastic.rb
|
22
22
|
- lib/arelastic/aggregations.rb
|
23
23
|
- lib/arelastic/aggregations/aggregation.rb
|
24
|
+
- lib/arelastic/aggregations/bucket.rb
|
24
25
|
- lib/arelastic/aggregations/date_histogram.rb
|
25
26
|
- lib/arelastic/aggregations/filter.rb
|
26
27
|
- lib/arelastic/aggregations/histogram.rb
|
27
28
|
- lib/arelastic/aggregations/min.rb
|
28
29
|
- lib/arelastic/aggregations/nested.rb
|
30
|
+
- lib/arelastic/aggregations/reverse_nested.rb
|
29
31
|
- lib/arelastic/aggregations/terms.rb
|
30
32
|
- lib/arelastic/arities.rb
|
31
33
|
- lib/arelastic/arities/binary.rb
|
@@ -102,9 +104,11 @@ files:
|
|
102
104
|
- lib/arelastic/sorts/geo_distance.rb
|
103
105
|
- lib/arelastic/sorts/sort.rb
|
104
106
|
- test/arelastic/aggregations/aggregation_test.rb
|
107
|
+
- test/arelastic/aggregations/bucket_test.rb
|
105
108
|
- test/arelastic/aggregations/date_histogram_test.rb
|
106
109
|
- test/arelastic/aggregations/filter_test.rb
|
107
110
|
- test/arelastic/aggregations/nested_test.rb
|
111
|
+
- test/arelastic/aggregations/reverse_nested_test.rb
|
108
112
|
- test/arelastic/aggregations/terms_test.rb
|
109
113
|
- test/arelastic/arities/binary_test.rb
|
110
114
|
- test/arelastic/arities/polyadic_test.rb
|
@@ -166,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
170
|
version: 1.8.11
|
167
171
|
requirements: []
|
168
172
|
rubyforge_project:
|
169
|
-
rubygems_version: 2.
|
173
|
+
rubygems_version: 2.6.11
|
170
174
|
signing_key:
|
171
175
|
specification_version: 4
|
172
176
|
summary: Elastic Search query builder
|