elasticsearch-dsl-builder 0.0.12 → 0.0.13

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: a58300aec0d5ee66159153ffe0cd8bc4a14e5fa8
4
- data.tar.gz: d9187ba6eb6c8017ea9039b957d30c8607c18176
3
+ metadata.gz: f0b148414b20b6644d211ecbc5ee92c7423888f5
4
+ data.tar.gz: 9db8534bc5557fc4d9c51fa9117c17ed675e5249
5
5
  SHA512:
6
- metadata.gz: e9941a0a509660fb524cbc6e527312d8014392e3a77a16583679e1b9b7e106b97438137c7e36aff095bc1765680522c089cc45e54f63848384b4a33ad2440738
7
- data.tar.gz: 1153f628e7b62acd9a24ff5d6ae5af324bc49ab9bf49ad0f029368dc87607bc88a83111374f60382b6126c33b897ee33f6bf7ff6581803da9cd9fd128e2fe3a9
6
+ metadata.gz: 94ae776602bde608971ef7ea3b1b240977a45cf88d3eb39c163208ea468bc0c92d265f699a8b4386689dd9ee4e0ff80eb8c89cb28d9e3815dc39210e39deb0fe
7
+ data.tar.gz: e1004ac5a0d17335e44cd3e3e65ea2e99e97645322db273015500f1142b8c1e27c76f764e5458cf2f897ef3fb7e12807d78e0c78099938167e578242baf7db31
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- elasticsearch-dsl-builder (0.0.12)
4
+ elasticsearch-dsl-builder (0.0.13)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'elasticsearch-dsl-builder'
3
- s.version = '0.0.12'
3
+ s.version = '0.0.13'
4
4
  s.date = '2017-10-06'
5
5
  s.summary = 'Library utilizing builder pattern providing Ruby API for the Elasticsearch Query DSL'
6
6
  s.description = 'TBD'
@@ -0,0 +1,26 @@
1
+ module ElasticsearchDslBuilder
2
+ module DSL
3
+ module Search
4
+ module Aggregations
5
+ class Nested < Aggregation
6
+ def initialize(path = nil)
7
+ @type = :nested
8
+ path(path)
9
+ super()
10
+ end
11
+
12
+ def path(path)
13
+ raise ArgumentError, 'path must be a String' unless path.instance_of?(String)
14
+ @path = path
15
+ self
16
+ end
17
+
18
+ def to_hash
19
+ @aggregation = { path: @path }
20
+ super
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -15,9 +15,15 @@ module ElasticsearchDslBuilder
15
15
  self
16
16
  end
17
17
 
18
+ def size(size)
19
+ raise ArgumentError, 'size must be Numeric' unless size.is_a?(Numeric)
20
+ @size = size
21
+ self
22
+ end
23
+
18
24
  def include(include)
19
25
  include_valid = include.instance_of?(String) ||
20
- (include.instance_of?(Array) && include.all? { |i| i.instance_of?(String)})
26
+ (include.instance_of?(Array) && include.all? { |i| i.instance_of?(String) })
21
27
  raise ArgumentError, 'include argument must be a String or Array of Strings' unless include_valid
22
28
  @include = include
23
29
  self
@@ -25,7 +31,7 @@ module ElasticsearchDslBuilder
25
31
 
26
32
  def exclude(exclude)
27
33
  exclude_valid = exclude.instance_of?(String) ||
28
- (exclude.instance_of?(Array) && exclude.all? { |i| i.instance_of?(String)})
34
+ (exclude.instance_of?(Array) && exclude.all? { |i| i.instance_of?(String) })
29
35
  raise ArgumentError, 'exclude argument must be a String or Array of Strings' unless exclude_valid
30
36
  @exclude = exclude
31
37
  self
@@ -33,6 +39,7 @@ module ElasticsearchDslBuilder
33
39
 
34
40
  def to_hash
35
41
  @aggregation = { field: @field }
42
+ @aggregation.update(size: @size) if @size
36
43
  @aggregation.update(include: @include) if @include
37
44
  @aggregation.update(exclude: @exclude) if @exclude
38
45
  super
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe ElasticsearchDslBuilder::DSL::Search::Aggregations::Nested do
4
+ it 'should fail if path not valid' do
5
+ expect { Aggregations::Nested.new(123) }.to raise_error(ArgumentError)
6
+ expect { Aggregations::Nested.new(nil) }.to raise_error(ArgumentError)
7
+ expect { Aggregations::Nested.new('path_a').path(nil) }.to raise_error(ArgumentError)
8
+ end
9
+
10
+ it 'should chain create valid ES aggregation hash' do
11
+ nested = Aggregations::Nested.new('path_a').path('path_b')
12
+ expect(nested.to_hash).to eq(
13
+ nested: { path: 'path_b' }
14
+ )
15
+ end
16
+ end
@@ -7,6 +7,11 @@ describe ElasticsearchDslBuilder::DSL::Search::Aggregations::Terms do
7
7
  expect { Aggregations::Terms.new('field_a').field(nil) }.to raise_error(ArgumentError)
8
8
  end
9
9
 
10
+ it 'should fail if size not valid' do
11
+ expect { Aggregations::Terms.new('field_a').size('fail') }.to raise_error(ArgumentError)
12
+ expect { Aggregations::Terms.new('field_a').size(nil) }.to raise_error(ArgumentError)
13
+ end
14
+
10
15
  it 'should fail if include not valid' do
11
16
  expect { Aggregations::Terms.new('field_a').include(nil) }.to raise_error(ArgumentError)
12
17
  expect { Aggregations::Terms.new('field_a').include({}) }.to raise_error(ArgumentError)
@@ -21,11 +26,12 @@ describe ElasticsearchDslBuilder::DSL::Search::Aggregations::Terms do
21
26
 
22
27
  it 'should chain create valid ES aggregation hash' do
23
28
  terms = Aggregations::Terms.new('field_a').
24
- include('*ball').exclude(%w(baseball racquetball)).
29
+ size(5).
30
+ include('*ball').exclude(['baseball', 'racquetball']).
25
31
  aggregation('nested_agg', Aggregations::Terms.new('field_b'))
26
32
  expect(terms.to_hash).to eq(
27
- terms: { field: 'field_a', include: '*ball', exclude: %w(baseball racquetball) },
28
- aggregations: { nested_agg: { terms: { field: 'field_b' } } }
29
- )
33
+ terms: { field: 'field_a', size: 5, include: '*ball', exclude: ['baseball', 'racquetball'] },
34
+ aggregations: { nested_agg: { terms: { field: 'field_b' } } }
35
+ )
30
36
  end
31
37
  end
@@ -17,12 +17,9 @@ describe ElasticsearchDslBuilder::DSL::Search::Queries::Range do
17
17
  range = Queries::Range.new(:field_a).
18
18
  format('YYYY-MM').gt('2017-09').gte('2017-09').lt('2017-09').lte('2017-09')
19
19
  expect(range.to_hash).to eq(
20
- range: {
21
- field_a: {
22
- gt: '2017-09', gte: '2017-09', lt: '2017-09', lte: '2017-09',
23
- format: 'YYYY-MM'
24
- }
25
- }
26
- )
20
+ range: {
21
+ field_a: { gt: '2017-09', gte: '2017-09', lt: '2017-09', lte: '2017-09', format: 'YYYY-MM' }
22
+ }
23
+ )
27
24
  end
28
25
  end
@@ -15,6 +15,6 @@ describe ElasticsearchDslBuilder::DSL::Search::Queries::Terms do
15
15
 
16
16
  it 'should chain create valid ES query hash' do
17
17
  terms = Queries::Terms.new(:field_a, [1, 2])
18
- expect(terms.to_hash).to eq({ terms: { field_a: [1, 2] } })
18
+ expect(terms.to_hash).to eq(terms: { field_a: [1, 2] })
19
19
  end
20
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch-dsl-builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marvin Guerra
@@ -85,6 +85,7 @@ files:
85
85
  - lib/elasticsearch_dsl_builder/dsl.rb
86
86
  - lib/elasticsearch_dsl_builder/dsl/search.rb
87
87
  - lib/elasticsearch_dsl_builder/dsl/search/aggregation.rb
88
+ - lib/elasticsearch_dsl_builder/dsl/search/aggregations/nested.rb
88
89
  - lib/elasticsearch_dsl_builder/dsl/search/aggregations/terms.rb
89
90
  - lib/elasticsearch_dsl_builder/dsl/search/queries/bool.rb
90
91
  - lib/elasticsearch_dsl_builder/dsl/search/queries/exists.rb
@@ -101,6 +102,7 @@ files:
101
102
  - lib/elasticsearch_dsl_builder/dsl/search/sort.rb
102
103
  - lib/elasticsearch_dsl_builder/dsl/version.rb
103
104
  - lib/elasticsearch_dsl_builder/exceptions.rb
105
+ - spec/lib/dsl/search/aggregations/nested_spec.rb
104
106
  - spec/lib/dsl/search/aggregations/terms_spec.rb
105
107
  - spec/lib/dsl/search/queries/bool_spec.rb
106
108
  - spec/lib/dsl/search/queries/exists_spec.rb
@@ -144,6 +146,7 @@ specification_version: 4
144
146
  summary: Library utilizing builder pattern providing Ruby API for the Elasticsearch
145
147
  Query DSL
146
148
  test_files:
149
+ - spec/lib/dsl/search/aggregations/nested_spec.rb
147
150
  - spec/lib/dsl/search/aggregations/terms_spec.rb
148
151
  - spec/lib/dsl/search/queries/bool_spec.rb
149
152
  - spec/lib/dsl/search/queries/exists_spec.rb