arelastic 0.7.0 → 0.8.0
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/aggregation.rb +6 -11
- data/lib/arelastic/aggregations/filter.rb +16 -0
- data/lib/arelastic/aggregations/min.rb +1 -1
- data/lib/arelastic/aggregations/nested.rb +24 -0
- data/lib/arelastic/aggregations/terms.rb +1 -1
- data/lib/arelastic/aggregations.rb +2 -0
- data/lib/arelastic/searches/aggregations.rb +9 -4
- data/test/arelastic/aggregations/filter_test.rb +33 -0
- data/test/arelastic/aggregations/nested_test.rb +4 -0
- data/test/arelastic/searches/aggregations_test.rb +51 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3dfdb1c53a2b4a1212dc4dc8c0bdeba81ae481f
|
4
|
+
data.tar.gz: b137778aaf23ff83245097e52bb334a443bbc465
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92ba970d8aa6fe7504d7746b76d3549d6529a295a3f863b6343ad5067035db3f869c41b69583fb16f4e440b61b21a641f892334d47ac19d884cb7a8e76e4faa5
|
7
|
+
data.tar.gz: 1ca4a168ca68149c6ebea89396672c1e5496c0a584ce87884b319378c0a3600fc5fd03268fd67a13699c63f80af2f0ffffe480e5519ab1a4cf948819908e7822
|
@@ -1,25 +1,20 @@
|
|
1
1
|
module Arelastic
|
2
2
|
module Aggregations
|
3
3
|
class Aggregation < Arelastic::Nodes::Node
|
4
|
-
attr_accessor :name, :options
|
4
|
+
attr_accessor :name, :options
|
5
5
|
|
6
|
-
def initialize(name, options)
|
6
|
+
def initialize(name, options = {})
|
7
7
|
@name = name
|
8
8
|
@options = options
|
9
9
|
end
|
10
10
|
|
11
11
|
def as_elastic
|
12
|
-
|
13
|
-
# if aggs.any?
|
14
|
-
# params['aggs'] = convert_to_elastic(aggs)
|
15
|
-
# end
|
16
|
-
|
17
|
-
{name => params}
|
12
|
+
{name => as_elastic_aggregation}
|
18
13
|
end
|
19
14
|
|
20
|
-
|
21
|
-
|
22
|
-
|
15
|
+
def as_elastic_aggregation
|
16
|
+
raise 'not implemented'
|
17
|
+
end
|
23
18
|
end
|
24
19
|
end
|
25
20
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Arelastic
|
2
|
+
module Aggregations
|
3
|
+
class Filter < Arelastic::Aggregations::Aggregation
|
4
|
+
attr_accessor :filter
|
5
|
+
|
6
|
+
def initialize name, filter
|
7
|
+
super name
|
8
|
+
@filter = filter
|
9
|
+
end
|
10
|
+
|
11
|
+
def as_elastic_aggregation
|
12
|
+
{'filter' => convert_to_elastic(filter)}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Arelastic
|
2
|
+
module Aggregations
|
3
|
+
class Nested < Arelastic::Aggregations::Aggregation
|
4
|
+
attr_accessor :path, :aggregations
|
5
|
+
|
6
|
+
# HashGroup
|
7
|
+
def initialize name, path, aggregations
|
8
|
+
super name
|
9
|
+
@path = path
|
10
|
+
@aggregations = aggregations
|
11
|
+
end
|
12
|
+
|
13
|
+
def as_elastic
|
14
|
+
grouping = Arelastic::Nodes::HashGroup.new aggregations
|
15
|
+
{
|
16
|
+
name => {
|
17
|
+
"nested" => {"path" => path},
|
18
|
+
"aggs" => grouping.as_elastic
|
19
|
+
}
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,13 +1,18 @@
|
|
1
1
|
module Arelastic
|
2
2
|
module Searches
|
3
3
|
class Aggregations < Arelastic::Searches::Search
|
4
|
-
attr_accessor :
|
5
|
-
def initialize aggregations
|
6
|
-
@
|
4
|
+
attr_accessor :aggregations
|
5
|
+
def initialize *aggregations
|
6
|
+
@aggregations = aggregations.flatten
|
7
7
|
end
|
8
8
|
|
9
9
|
def as_elastic
|
10
|
-
|
10
|
+
grouping = Arelastic::Nodes::HashGroup.new aggregations.flatten
|
11
|
+
{ "aggs" => grouping.as_elastic }
|
12
|
+
end
|
13
|
+
|
14
|
+
def nested(name, path)
|
15
|
+
Arelastic::Aggregations::Nested.new name, path, aggregations
|
11
16
|
end
|
12
17
|
end
|
13
18
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::Aggregations::TermsTest < MiniTest::Unit::TestCase
|
4
|
+
def test_as_elastic
|
5
|
+
aggregation = Arelastic::Aggregations::Filter.new('foo', 'exists' => {'field' => 'color'})
|
6
|
+
expected = {
|
7
|
+
"foo" => {
|
8
|
+
"filter" => {
|
9
|
+
"exists" => {
|
10
|
+
"field" => "color"
|
11
|
+
}
|
12
|
+
}
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
assert_equal expected, aggregation.as_elastic
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_as_elastic_with_node
|
20
|
+
aggregation = Arelastic::Aggregations::Filter.new('foo', Arelastic::Filters::Exists.new('color'))
|
21
|
+
expected = {
|
22
|
+
"foo" => {
|
23
|
+
"filter" => {
|
24
|
+
"exists" => {
|
25
|
+
"field" => "color"
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
assert_equal expected, aggregation.as_elastic
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::Searches::AggregationsTest < MiniTest::Spec
|
4
|
+
def test_as_elastic
|
5
|
+
aggregations = Arelastic::Searches::Aggregations.new(
|
6
|
+
Arelastic::Aggregations::Terms.new('popular_tags', 'field' => 'tags', 'size' => 10),
|
7
|
+
"colorful" => {"filter" => {"exists" => {"field" => "color"}}}
|
8
|
+
)
|
9
|
+
|
10
|
+
expected = {
|
11
|
+
"aggs" => {
|
12
|
+
"popular_tags" => {
|
13
|
+
"terms" => {
|
14
|
+
"field" => "tags",
|
15
|
+
"size" => 10
|
16
|
+
}
|
17
|
+
},
|
18
|
+
"colorful" => {
|
19
|
+
"filter" => {
|
20
|
+
"exists" => {
|
21
|
+
"field" => "color"
|
22
|
+
}
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}
|
26
|
+
}
|
27
|
+
assert_equal expected, aggregations.as_elastic
|
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
|
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: 0.
|
4
|
+
version: 0.8.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: 2015-
|
11
|
+
date: 2015-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Build Elastic Search queries with objects
|
14
14
|
email: developer@matthewhiggins.com
|
@@ -21,7 +21,9 @@ files:
|
|
21
21
|
- lib/arelastic.rb
|
22
22
|
- lib/arelastic/aggregations.rb
|
23
23
|
- lib/arelastic/aggregations/aggregation.rb
|
24
|
+
- lib/arelastic/aggregations/filter.rb
|
24
25
|
- lib/arelastic/aggregations/min.rb
|
26
|
+
- lib/arelastic/aggregations/nested.rb
|
25
27
|
- lib/arelastic/aggregations/terms.rb
|
26
28
|
- lib/arelastic/arities.rb
|
27
29
|
- lib/arelastic/arities/binary.rb
|
@@ -100,6 +102,8 @@ files:
|
|
100
102
|
- lib/arelastic/sorts.rb
|
101
103
|
- lib/arelastic/sorts/asc.rb
|
102
104
|
- lib/arelastic/sorts/sort.rb
|
105
|
+
- test/arelastic/aggregations/filter_test.rb
|
106
|
+
- test/arelastic/aggregations/nested_test.rb
|
103
107
|
- test/arelastic/aggregations/terms_test.rb
|
104
108
|
- test/arelastic/arities/binary_test.rb
|
105
109
|
- test/arelastic/arities/polyadic_test.rb
|
@@ -138,6 +142,7 @@ files:
|
|
138
142
|
- test/arelastic/queries/query_string_test.rb
|
139
143
|
- test/arelastic/queries/query_test.rb
|
140
144
|
- test/arelastic/queries/wildcard_test.rb
|
145
|
+
- test/arelastic/searches/aggregations_test.rb
|
141
146
|
- test/arelastic/searches/sort_test.rb
|
142
147
|
- test/arelastic/sorts/sort_test.rb
|
143
148
|
- test/helper.rb
|