elasticsearch-dsl-builder 0.0.12 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/elasticsearch-dsl-builder.gemspec +1 -1
- data/lib/elasticsearch_dsl_builder/dsl/search/aggregations/nested.rb +26 -0
- data/lib/elasticsearch_dsl_builder/dsl/search/aggregations/terms.rb +9 -2
- data/spec/lib/dsl/search/aggregations/nested_spec.rb +16 -0
- data/spec/lib/dsl/search/aggregations/terms_spec.rb +10 -4
- data/spec/lib/dsl/search/queries/range_spec.rb +4 -7
- data/spec/lib/dsl/search/queries/terms_spec.rb +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0b148414b20b6644d211ecbc5ee92c7423888f5
|
4
|
+
data.tar.gz: 9db8534bc5557fc4d9c51fa9117c17ed675e5249
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94ae776602bde608971ef7ea3b1b240977a45cf88d3eb39c163208ea468bc0c92d265f699a8b4386689dd9ee4e0ff80eb8c89cb28d9e3815dc39210e39deb0fe
|
7
|
+
data.tar.gz: e1004ac5a0d17335e44cd3e3e65ea2e99e97645322db273015500f1142b8c1e27c76f764e5458cf2f897ef3fb7e12807d78e0c78099938167e578242baf7db31
|
data/Gemfile.lock
CHANGED
@@ -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
|
-
|
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
|
-
|
28
|
-
|
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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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(
|
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.
|
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
|