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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b7e6147284908ea72345b434db648ed51a887286
4
- data.tar.gz: a992f57aee01a9b9541ceb4f844c0ca8a7ee1318
3
+ metadata.gz: e3dfdb1c53a2b4a1212dc4dc8c0bdeba81ae481f
4
+ data.tar.gz: b137778aaf23ff83245097e52bb334a443bbc465
5
5
  SHA512:
6
- metadata.gz: 8bf09de6b0fabf1834878b3ee0e7194a952e60f0a2b99ba177e4c399af754ccc46ca69a437a5503aacf555221a74f479b5b03f392f18aaab69dc84defca5d9aa
7
- data.tar.gz: 274c22454a4a8b1646e2a71069dc004671ee87d363b988701f9cb11d553b97114c9b58d2b8719163000e5c4ae57b86ba6e9b4e0b3109080f22f2e5e79214dec6
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, :aggs
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
- params = as_elastic_aggregation
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
- # def nested path
21
- # Arelastic::Aggregations::Nested.new path, self
22
- # end
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
@@ -4,7 +4,7 @@ module Arelastic
4
4
  attr_accessor :options
5
5
 
6
6
  def initialize name, options
7
- # @field = field
7
+ super name
8
8
  @options = options
9
9
  end
10
10
 
@@ -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
@@ -2,7 +2,7 @@ module Arelastic
2
2
  module Aggregations
3
3
  class Terms < Arelastic::Aggregations::Aggregation
4
4
  def as_elastic_aggregation
5
- {"terms" => options}
5
+ {'terms' => options}
6
6
  end
7
7
  end
8
8
  end
@@ -1,3 +1,5 @@
1
1
  require 'arelastic/aggregations/aggregation'
2
2
 
3
+ require 'arelastic/aggregations/filter'
4
+ require 'arelastic/aggregations/nested'
3
5
  require 'arelastic/aggregations/terms'
@@ -1,13 +1,18 @@
1
1
  module Arelastic
2
2
  module Searches
3
3
  class Aggregations < Arelastic::Searches::Search
4
- attr_accessor :grouping
5
- def initialize aggregations
6
- @grouping = Arelastic::Nodes::HashGroup.new aggregations
4
+ attr_accessor :aggregations
5
+ def initialize *aggregations
6
+ @aggregations = aggregations.flatten
7
7
  end
8
8
 
9
9
  def as_elastic
10
- { "aggs" => convert_to_elastic(grouping) }
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,4 @@
1
+ require 'helper'
2
+
3
+ class Arelastic::Aggregations::NestedTest < MiniTest::Unit::TestCase
4
+ 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.7.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-01-23 00:00:00.000000000 Z
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