elasticsearch-dsl-builder 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/elasticsearch-dsl-builder.gemspec +1 -1
  3. data/lib/elasticsearch_dsl_builder/dsl.rb +1 -1
  4. data/lib/elasticsearch_dsl_builder/dsl/search/aggregations/cardinality.rb +33 -0
  5. data/lib/elasticsearch_dsl_builder/dsl/search/aggregations/children.rb +26 -0
  6. data/lib/elasticsearch_dsl_builder/dsl/search/aggregations/date_histogram.rb +40 -0
  7. data/lib/elasticsearch_dsl_builder/dsl/search/aggregations/date_range.rb +56 -0
  8. data/lib/elasticsearch_dsl_builder/dsl/search/aggregations/filter.rb +26 -0
  9. data/lib/elasticsearch_dsl_builder/dsl/search/aggregations/filters.rb +40 -0
  10. data/lib/elasticsearch_dsl_builder/dsl/search/aggregations/geohash_grid.rb +47 -0
  11. data/lib/elasticsearch_dsl_builder/dsl/search/aggregations/range.rb +57 -0
  12. data/lib/elasticsearch_dsl_builder/dsl/search/aggregations/stats.rb +40 -0
  13. data/lib/elasticsearch_dsl_builder/dsl/search/aggregations/sum.rb +40 -0
  14. data/lib/elasticsearch_dsl_builder/dsl/search/aggregations/sum_bucket.rb +41 -0
  15. data/lib/elasticsearch_dsl_builder/dsl/search/aggregations/terms.rb +8 -2
  16. data/lib/elasticsearch_dsl_builder/dsl/search/queries/exists.rb +1 -1
  17. data/lib/elasticsearch_dsl_builder/dsl/search/queries/geo_bounding_box.rb +61 -0
  18. data/lib/elasticsearch_dsl_builder/dsl/search/queries/terms.rb +1 -1
  19. data/lib/elasticsearch_dsl_builder/dsl/search/script.rb +42 -0
  20. data/spec/lib/dsl/search/aggregations/cardinality_spec.rb +28 -0
  21. data/spec/lib/dsl/search/aggregations/children_spec.rb +14 -0
  22. data/spec/lib/dsl/search/aggregations/date_histogram_spec.rb +26 -0
  23. data/spec/lib/dsl/search/aggregations/date_range_spec.rb +44 -0
  24. data/spec/lib/dsl/search/aggregations/filter_spec.rb +14 -0
  25. data/spec/lib/dsl/search/aggregations/filters_spec.rb +32 -0
  26. data/spec/lib/dsl/search/aggregations/geohash_grid_spec.rb +29 -0
  27. data/spec/lib/dsl/search/aggregations/range_spec.rb +43 -0
  28. data/spec/lib/dsl/search/aggregations/stats_spec.rb +20 -0
  29. data/spec/lib/dsl/search/aggregations/sum_bucket_spec.rb +24 -0
  30. data/spec/lib/dsl/search/aggregations/sum_spec.rb +20 -0
  31. data/spec/lib/dsl/search/aggregations/terms_spec.rb +29 -14
  32. data/spec/lib/dsl/search/queries/geo_bounding_box_spec.rb +53 -0
  33. data/spec/lib/dsl/search/script_spec.rb +36 -0
  34. data/spec/lib/dsl/search_spec.rb +1 -1
  35. metadata +40 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d4b68f810a7e501951cafe0ace207769c6c03d36
4
- data.tar.gz: d25a1c5fdccf86444559be220f9a3464ec488a85
3
+ metadata.gz: 3cd56b7c2da3fde323d2b45b9a44cfa90aa2ad1b
4
+ data.tar.gz: 8d3cbbd3d97b17a88ca1ba879c38eb4981e4a09d
5
5
  SHA512:
6
- metadata.gz: f6b5b0f60006cd83e625489ea03b14ac26fe47fc9dc30e0f31686eb39e23d3cb2e6618cd060fbf0401998aed156ad2b9df696d38bb3e942ddd3f8774dd6f0e7f
7
- data.tar.gz: d08ed977c1887649bae135bd57b90b5bbb718ad979cdc9c012b0fa96b675cc036fe0773b7face50156c87d0c499566756f42a9fba3a74b613dea1e8e6d83af02
6
+ metadata.gz: d78f1a2d967897f2b5e39125ab947792c3226dce95a6c9ed17bfc5e42c928e3202a46a31e5b2d2f7fdd65768f4f96027f3629282d67d3c8bde9b13234dd3f014
7
+ data.tar.gz: 349e21160f7121ae9ba3882721968961ccb2c5fe8c7ac87d5c2bb4e8e8e824b32db227388520933a78672c849e481874f667785faa6b2174c9580477f9912929
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'elasticsearch-dsl-builder'
3
- s.version = '0.0.14'
3
+ s.version = '0.0.15'
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'
@@ -2,11 +2,11 @@ require 'elasticsearch_dsl_builder/dsl/version'
2
2
 
3
3
  require 'elasticsearch_dsl_builder/dsl/search/aggregation'
4
4
  require 'elasticsearch_dsl_builder/dsl/search/query'
5
+ require 'elasticsearch_dsl_builder/dsl/search/script'
5
6
  require 'elasticsearch_dsl_builder/dsl/search/sort'
6
7
  require 'elasticsearch_dsl_builder/exceptions'
7
8
 
8
9
  Dir[File.expand_path('../dsl/search/queries/**/*.rb', __FILE__)].each { |f| require f }
9
- Dir[File.expand_path('../dsl/search/filters/**/*.rb', __FILE__)].each { |f| require f }
10
10
  Dir[File.expand_path('../dsl/search/aggregations/**/*.rb', __FILE__)].each { |f| require f }
11
11
 
12
12
  require 'elasticsearch_dsl_builder/dsl/search'
@@ -0,0 +1,33 @@
1
+ module ElasticsearchDslBuilder
2
+ module DSL
3
+ module Search
4
+ module Aggregations
5
+ class Cardinality < Aggregation
6
+ def initialize
7
+ @type = :cardinality
8
+ super()
9
+ end
10
+
11
+ def field(field)
12
+ raise ArgumentError, 'field must be a String' unless field.instance_of?(String)
13
+ @field = field
14
+ self
15
+ end
16
+
17
+ def script(script)
18
+ raise ArgumentError, 'script must be a Script' unless script.instance_of?(Script)
19
+ @script = script.to_hash
20
+ self
21
+ end
22
+
23
+ def to_hash
24
+ @aggregation = {}
25
+ @aggregation.update(field: @field) if @field
26
+ @aggregation.update(script: @script) if @script
27
+ super
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,26 @@
1
+ module ElasticsearchDslBuilder
2
+ module DSL
3
+ module Search
4
+ module Aggregations
5
+ class Children < Aggregation
6
+ def initialize(type)
7
+ @type = :children
8
+ type(type)
9
+ super()
10
+ end
11
+
12
+ def type(type)
13
+ raise ArgumentError, 'type must be a String' unless type.instance_of?(String)
14
+ @child_type = type
15
+ self
16
+ end
17
+
18
+ def to_hash
19
+ @aggregation = { type: @child_type }
20
+ super
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,40 @@
1
+ module ElasticsearchDslBuilder
2
+ module DSL
3
+ module Search
4
+ module Aggregations
5
+ class DateHistogram < Aggregation
6
+ def initialize(field = nil, interval = nil)
7
+ @type = :date_histogram
8
+ field(field)
9
+ interval(interval)
10
+ super()
11
+ end
12
+
13
+ def field(field)
14
+ raise ArgumentError, 'field must be a String' unless field.instance_of?(String)
15
+ @field = field
16
+ self
17
+ end
18
+
19
+ def interval(interval)
20
+ raise ArgumentError, 'interval must be a String' unless interval.instance_of?(String)
21
+ @interval = interval
22
+ self
23
+ end
24
+
25
+ def format(format)
26
+ raise ArgumentError, 'format must be a String' unless format.instance_of?(String)
27
+ @format = format
28
+ self
29
+ end
30
+
31
+ def to_hash
32
+ @aggregation = { field: @field, interval: @interval }
33
+ @aggregation.update(format: @format) if @format
34
+ super
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,56 @@
1
+ module ElasticsearchDslBuilder
2
+ module DSL
3
+ module Search
4
+ module Aggregations
5
+ class DateRange < Aggregation
6
+ def initialize(field = nil)
7
+ @type = :date_range
8
+ field(field)
9
+ super()
10
+ end
11
+
12
+ def field(field)
13
+ raise ArgumentError, 'field must be a String' unless field.instance_of?(String)
14
+ @field = field
15
+ self
16
+ end
17
+
18
+ def format(format)
19
+ raise ArgumentError, 'format must be a String' unless format.instance_of?(String)
20
+ @format = format
21
+ self
22
+ end
23
+
24
+ def keyed(keyed)
25
+ raise ArgumentError, 'keyed must be a boolean' unless !!keyed == keyed
26
+ @keyed = keyed
27
+ self
28
+ end
29
+
30
+ def range(from: nil, to: nil, key: nil)
31
+ @ranges ||= []
32
+ raise ArgumentError, 'must pass at least one of from or to' if from.nil? && to.nil?
33
+ from_valid = from.instance_of?(String) || from.is_a?(Numeric)
34
+ raise ArgumentError, 'from must be String or Numeric' if !from.nil? && !from_valid
35
+ to_valid = to.instance_of?(String) || to.is_a?(Numeric)
36
+ raise ArgumentError, 'to must be String or Numeric' if !to.nil? && !to_valid
37
+ range = {}
38
+ range.update(from: from) if from
39
+ range.update(to: to) if to
40
+ range.update(key: key) if key
41
+ @ranges << range
42
+ self
43
+ end
44
+
45
+ def to_hash
46
+ @aggregation = { field: @field }
47
+ @aggregation.update(format: @format) if @format
48
+ @aggregation.update(keyed: @keyed) if @keyed
49
+ @aggregation.update(ranges: @ranges) if @ranges
50
+ super
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,26 @@
1
+ module ElasticsearchDslBuilder
2
+ module DSL
3
+ module Search
4
+ module Aggregations
5
+ class Filter < Aggregation
6
+ def initialize(query)
7
+ @type = :filter
8
+ filter(query)
9
+ super()
10
+ end
11
+
12
+ def filter(query)
13
+ raise ArgumentError, 'query must be a Queries::Query' unless query.is_a?(Queries::Query)
14
+ @query = query.to_hash
15
+ self
16
+ end
17
+
18
+ def to_hash
19
+ @aggregation = @query
20
+ super
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,40 @@
1
+ module ElasticsearchDslBuilder
2
+ module DSL
3
+ module Search
4
+ module Aggregations
5
+ class Filters < Aggregation
6
+ def initialize
7
+ @type = :filters
8
+ super()
9
+ end
10
+
11
+ def filter(query, name = nil)
12
+ raise ArgumentError, 'query must extend type Queries::Query' unless query.is_a?(Queries::Query)
13
+ query = query.to_hash
14
+
15
+ if name.nil?
16
+ # Adding an anonymous filter
17
+ raise ArgumentError, 'this aggregation already contains named filters. cannot mix' if @filters.instance_of?(Hash)
18
+ @filters ||= []
19
+ @filters << query
20
+ else
21
+ # Adding named filter
22
+ raise ArgumentError, 'this aggregation already contains anonymous filters. cannot mix' if @filters.instance_of?(Array)
23
+ name_valid = name.instance_of?(String) || name.instance_of?(Symbol)
24
+ raise ArgumentError, 'name must be a String or Symbol' unless name_valid
25
+ @filters ||= {}
26
+ @filters[name.to_sym] = query
27
+ end
28
+ self
29
+ end
30
+
31
+ def to_hash
32
+ raise ArgumentError, 'no filters were added' if @filters.nil?
33
+ @aggregation = { filters: @filters }
34
+ super
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,47 @@
1
+ module ElasticsearchDslBuilder
2
+ module DSL
3
+ module Search
4
+ module Aggregations
5
+ class GeohashGrid < Aggregation
6
+ def initialize(field)
7
+ @type = :geohash_grid
8
+ field(field)
9
+ super()
10
+ end
11
+
12
+ def field(field)
13
+ raise ArgumentError, 'field must be a String' unless field.instance_of?(String)
14
+ @field = field
15
+ self
16
+ end
17
+
18
+ def precision(precision)
19
+ raise ArgumentError, 'precision must be a Numeric' unless precision.is_a?(Numeric)
20
+ @precision = precision
21
+ self
22
+ end
23
+
24
+ def size(size)
25
+ raise ArgumentError, 'size must be a Numeric' unless size.is_a?(Numeric)
26
+ @size = size
27
+ self
28
+ end
29
+
30
+ def shard_size(shard_size)
31
+ raise ArgumentError, 'shard_size must be a Numeric' unless shard_size.is_a?(Numeric)
32
+ @shard_size = shard_size
33
+ self
34
+ end
35
+
36
+ def to_hash
37
+ @aggregation = { field: @field }
38
+ @aggregation.update(precision: @precision) if @precision
39
+ @aggregation.update(size: @size) if @size
40
+ @aggregation.update(shard_size: @shard_size) if @shard_size
41
+ super
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,57 @@
1
+ module ElasticsearchDslBuilder
2
+ module DSL
3
+ module Search
4
+ module Aggregations
5
+ class Range < Aggregation
6
+ def initialize
7
+ @type = :range
8
+ super()
9
+ end
10
+
11
+ def field(field)
12
+ raise ArgumentError, 'field must be a String' unless field.instance_of?(String)
13
+ @field = field
14
+ self
15
+ end
16
+
17
+ def script(script)
18
+ raise ArgumentError, 'script must be a Script' unless script.instance_of?(Script)
19
+ @script = script.to_hash
20
+ self
21
+ end
22
+
23
+ def keyed(keyed)
24
+ raise ArgumentError, 'keyed must be a boolean' unless !!keyed == keyed
25
+ @keyed = keyed
26
+ self
27
+ end
28
+
29
+ def range(from: nil, to: nil, key: nil)
30
+ @ranges ||= []
31
+ raise ArgumentError, 'must pass at least one of from or to' if from.nil? && to.nil?
32
+ from_valid = from.instance_of?(String) || from.is_a?(Numeric)
33
+ raise ArgumentError, 'from must be String or Numeric' if !from.nil? && !from_valid
34
+ to_valid = to.instance_of?(String) || to.is_a?(Numeric)
35
+ raise ArgumentError, 'to must be String or Numeric' if !to.nil? && !to_valid
36
+ range = {}
37
+ range.update(from: from) if from
38
+ range.update(to: to) if to
39
+ range.update(key: key) if key
40
+ @ranges << range
41
+ self
42
+ end
43
+
44
+ def to_hash
45
+ raise ArgumentError, 'must have set at least one of [field, script]' if @field.nil? && @script.nil?
46
+ @aggregation = {}
47
+ @aggregation.update(field: @field) if @field
48
+ @aggregation.update(script: @script) if @script
49
+ @aggregation.update(keyed: @keyed) if @keyed
50
+ @aggregation.update(ranges: @ranges) if @ranges
51
+ super
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,40 @@
1
+ module ElasticsearchDslBuilder
2
+ module DSL
3
+ module Search
4
+ module Aggregations
5
+ class Stats < Aggregation
6
+ def initialize
7
+ @type = :stats
8
+ super()
9
+ end
10
+
11
+ def field(field)
12
+ raise ArgumentError, 'field must be a String' unless field.instance_of?(String)
13
+ @field = field
14
+ self
15
+ end
16
+
17
+ def script(script)
18
+ raise ArgumentError, 'script must be a Script' unless script.instance_of?(Script)
19
+ @script = script.to_hash
20
+ self
21
+ end
22
+
23
+ def missing(missing)
24
+ @missing = missing
25
+ self
26
+ end
27
+
28
+ def to_hash
29
+ raise ArgumentError, 'must have set at least one of [field, script]' if @field.nil? && @script.nil?
30
+ @aggregation = {}
31
+ @aggregation.update(field: @field) if @field
32
+ @aggregation.update(script: @script) if @script
33
+ @aggregation.update(missing: @missing) if @missing
34
+ super
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,40 @@
1
+ module ElasticsearchDslBuilder
2
+ module DSL
3
+ module Search
4
+ module Aggregations
5
+ class Sum < Aggregation
6
+ def initialize
7
+ @type = :sum
8
+ super()
9
+ end
10
+
11
+ def field(field)
12
+ raise ArgumentError, 'field must be a String' unless field.instance_of?(String)
13
+ @field = field
14
+ self
15
+ end
16
+
17
+ def script(script)
18
+ raise ArgumentError, 'script must be a Script' unless script.instance_of?(Script)
19
+ @script = script.to_hash
20
+ self
21
+ end
22
+
23
+ def missing(missing)
24
+ @missing = missing
25
+ self
26
+ end
27
+
28
+ def to_hash
29
+ raise ArgumentError, 'must have set at least one of [field, script]' if @field.nil? && @script.nil?
30
+ @aggregation = {}
31
+ @aggregation.update(field: @field) if @field
32
+ @aggregation.update(script: @script) if @script
33
+ @aggregation.update(missing: @missing) if @missing
34
+ super
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,41 @@
1
+ module ElasticsearchDslBuilder
2
+ module DSL
3
+ module Search
4
+ module Aggregations
5
+ class SumBucket < Aggregation
6
+ def initialize(buckets_path)
7
+ @type = :sum_bucket
8
+ buckets_path(buckets_path)
9
+ super()
10
+ end
11
+
12
+ def buckets_path(buckets_path)
13
+ raise ArgumentError, 'buckets_path must be a String' unless buckets_path.instance_of?(String)
14
+ @buckets_path = buckets_path
15
+ self
16
+ end
17
+
18
+ def gap_policy(gap_policy)
19
+ raise ArgumentError, 'gap_policy must be a String' unless gap_policy.instance_of?(String)
20
+ @gap_policy = gap_policy
21
+ self
22
+ end
23
+
24
+ def format(format)
25
+ raise ArgumentError, 'format must be a String' unless format.instance_of?(String)
26
+ @format = format
27
+ self
28
+ end
29
+
30
+ def to_hash
31
+ @aggregation = { buckets_path: @buckets_path }
32
+ @aggregation.update(field: @field) if @field
33
+ @aggregation.update(gap_policy: @gap_policy) if @gap_policy
34
+ @aggregation.update(format: @format) if @format
35
+ super
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -3,9 +3,8 @@ module ElasticsearchDslBuilder
3
3
  module Search
4
4
  module Aggregations
5
5
  class Terms < Aggregation
6
- def initialize(field = nil)
6
+ def initialize
7
7
  @type = :terms
8
- field(field)
9
8
  super()
10
9
  end
11
10
 
@@ -15,6 +14,12 @@ module ElasticsearchDslBuilder
15
14
  self
16
15
  end
17
16
 
17
+ def script(script)
18
+ raise ArgumentError, 'script must be a Script' unless script.instance_of?(Script)
19
+ @script = script.to_hash
20
+ self
21
+ end
22
+
18
23
  def size(size)
19
24
  raise ArgumentError, 'size must be Numeric' unless size.is_a?(Numeric)
20
25
  @size = size
@@ -39,6 +44,7 @@ module ElasticsearchDslBuilder
39
44
 
40
45
  def to_hash
41
46
  @aggregation = { field: @field }
47
+ @aggregation.update(script: @script) if @script
42
48
  @aggregation.update(size: @size) if @size
43
49
  @aggregation.update(include: @include) if @include
44
50
  @aggregation.update(exclude: @exclude) if @exclude
@@ -3,7 +3,7 @@ module ElasticsearchDslBuilder
3
3
  module Search
4
4
  module Queries
5
5
  class Exists < Query
6
- def initialize(field = nil)
6
+ def initialize(field)
7
7
  @type = :exists
8
8
  field(field)
9
9
  super()
@@ -0,0 +1,61 @@
1
+ module ElasticsearchDslBuilder
2
+ module DSL
3
+ module Search
4
+ module Queries
5
+ class GeoBoundingBox < Query
6
+ def initialize(field)
7
+ @type = :geo_bounding_box
8
+ field(field)
9
+ super()
10
+ end
11
+
12
+ def field(field)
13
+ field_valid = field.instance_of?(String) || field.instance_of?(Symbol)
14
+ raise ArgumentError, 'field must be a String or Symbol' unless field_valid
15
+ @field = field.to_sym
16
+ self
17
+ end
18
+
19
+ def top_left(lat, lon)
20
+ raise ArgumentError, 'lat must be numeric' unless lat.is_a?(Numeric)
21
+ raise ArgumentError, 'lon must be numeric' unless lon.is_a?(Numeric)
22
+ @top_left = { lat: lat, lon: lon }
23
+ self
24
+ end
25
+
26
+ def top_left_geohash(geohash)
27
+ raise ArgumentError, 'geohash must be a String' unless geohash.instance_of?(String)
28
+ @top_left = geohash
29
+ self
30
+ end
31
+
32
+ def bottom_right(lat, lon)
33
+ raise ArgumentError, 'lat must be numeric' unless lat.is_a?(Numeric)
34
+ raise ArgumentError, 'lon must be numeric' unless lon.is_a?(Numeric)
35
+ @bottom_right = { lat: lat, lon: lon }
36
+ self
37
+ end
38
+
39
+ def bottom_right_geohash(geohash)
40
+ raise ArgumentError, 'geohash must be a String' unless geohash.instance_of?(String)
41
+ @bottom_right = geohash
42
+ self
43
+ end
44
+
45
+ def type(type)
46
+ raise ArgumentError, 'type must be a String' unless type.instance_of?(String)
47
+ @geo_type = type
48
+ self
49
+ end
50
+
51
+ def to_hash
52
+ raise ArgumentError, 'must have set bounding box' if @top_left.nil? || @bottom_right.nil?
53
+ @query = { @field => { top_left: @top_left, bottom_right: @bottom_right } }
54
+ @query.update(type: @geo_type) if @geo_type
55
+ super
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -19,7 +19,7 @@ module ElasticsearchDslBuilder
19
19
 
20
20
  def field(field)
21
21
  field_valid = field.instance_of?(String) || field.instance_of?(Symbol)
22
- raise ArgumentError, 'field must be a String' unless field_valid
22
+ raise ArgumentError, 'field must be a String or Symbol' unless field_valid
23
23
  @field = field.to_sym
24
24
  self
25
25
  end
@@ -0,0 +1,42 @@
1
+ module ElasticsearchDslBuilder
2
+ module DSL
3
+ module Search
4
+ class Script
5
+ def lang(lang)
6
+ raise ArgumentError, 'lang must be a String' unless lang.instance_of?(String)
7
+ @lang = lang
8
+ self
9
+ end
10
+
11
+ def source(source)
12
+ raise ArgumentError, 'can be inline or file script. not both' if @file
13
+ raise ArgumentError, 'source must be a String' unless source.instance_of?(String)
14
+ @source = source
15
+ self
16
+ end
17
+
18
+ def file(file)
19
+ raise ArgumentError, 'can be inline or file script. not both' if @source
20
+ raise ArgumentError, 'file must be a String' unless file.instance_of?(String)
21
+ @file = file
22
+ self
23
+ end
24
+
25
+ def params(params)
26
+ raise ArgumentError, 'params must be a hash' unless params.instance_of?(Hash)
27
+ @params = params
28
+ self
29
+ end
30
+
31
+ def to_hash
32
+ script = {}
33
+ @lang ||= 'painless'
34
+ script.update(lang: @lang, source: @source) if @source
35
+ script.update(file: @file) if @file
36
+ script.update(params: @params) if @params
37
+ script
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe ElasticsearchDslBuilder::DSL::Search::Aggregations::Cardinality do
4
+ it 'should fail if field not valid' do
5
+ expect { Aggregations::Cardinality.new.field(123) }.to raise_error(ArgumentError)
6
+ expect { Aggregations::Cardinality.new.field(nil) }.to raise_error(ArgumentError)
7
+ end
8
+
9
+ it 'should fail if script is not valid' do
10
+ expect { Aggregations::Cardinality.new.script(Script.new.source('source').file('file')) }.to raise_error(ArgumentError)
11
+ expect { Aggregations::Cardinality.new.script(Script.new.source(123)) }.to raise_error(ArgumentError)
12
+ expect { Aggregations::Cardinality.new.script(Script.new.file(123)) }.to raise_error(ArgumentError)
13
+ expect { Aggregations::Cardinality.new.script(Script.new.source('source').lang(123)) }.to raise_error(ArgumentError)
14
+ expect { Aggregations::Cardinality.new.script(Script.new.source('source').params(123)) }.to raise_error(ArgumentError)
15
+ end
16
+
17
+ it 'should chain create valid ES aggregation hash' do
18
+ cardinality = Aggregations::Cardinality.new.field('field_b').script(Script.new.source('source').params(field: 'value'))
19
+ expect(cardinality.to_hash).to eq(
20
+ cardinality: { field: 'field_b', script: { lang: 'painless', source: 'source', params: { field: 'value' } } }
21
+ )
22
+
23
+ cardinality = Aggregations::Cardinality.new.field('field_b').script(Script.new.file('file').params(field: 'value'))
24
+ expect(cardinality.to_hash).to eq(
25
+ cardinality: { field: 'field_b', script: { file: 'file', params: { field: 'value' } } }
26
+ )
27
+ end
28
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe ElasticsearchDslBuilder::DSL::Search::Aggregations::Children do
4
+ it 'should fail if type not valid' do
5
+ expect { Aggregations::Children.new(123) }.to raise_error(ArgumentError)
6
+ expect { Aggregations::Children.new(nil) }.to raise_error(ArgumentError)
7
+ expect { Aggregations::Children.new('valid').type(nil) }.to raise_error(ArgumentError)
8
+ end
9
+
10
+ it 'should chain create valid ES aggregation hash' do
11
+ children = Aggregations::Children.new('type_a')
12
+ expect(children.to_hash).to eq(children: { type: 'type_a' })
13
+ end
14
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe ElasticsearchDslBuilder::DSL::Search::Aggregations::DateHistogram do
4
+ it 'should fail if field not valid' do
5
+ expect { Aggregations::DateHistogram.new(123, 'month') }.to raise_error(ArgumentError)
6
+ expect { Aggregations::DateHistogram.new(nil, 'month') }.to raise_error(ArgumentError)
7
+ expect { Aggregations::DateHistogram.new('field_a', 'month').field(nil) }.to raise_error(ArgumentError)
8
+ end
9
+
10
+ it 'should fail if interval not valid' do
11
+ expect { Aggregations::DateHistogram.new('field_a', 1) }.to raise_error(ArgumentError)
12
+ expect { Aggregations::DateHistogram.new('field_a') }.to raise_error(ArgumentError)
13
+ expect { Aggregations::DateHistogram.new('field_a', nil) }.to raise_error(ArgumentError)
14
+ expect { Aggregations::DateHistogram.new('field_a', 'month').interval(nil) }.to raise_error(ArgumentError)
15
+ end
16
+
17
+ it 'should fail if format not valid' do
18
+ expect { Aggregations::DateHistogram.new('field_a').format(123) }.to raise_error(ArgumentError)
19
+ expect { Aggregations::DateHistogram.new('field_a').format(nil) }.to raise_error(ArgumentError)
20
+ end
21
+
22
+ it 'should chain create valid ES aggregation hash' do
23
+ date_histogram = Aggregations::DateHistogram.new('field_a', 'month').format('MM-yyy')
24
+ expect(date_histogram.to_hash).to eq(date_histogram: { field: 'field_a', interval: 'month', format: 'MM-yyy' })
25
+ end
26
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe ElasticsearchDslBuilder::DSL::Search::Aggregations::DateRange do
4
+ it 'should fail if field not valid' do
5
+ expect { Aggregations::DateRange.new(123) }.to raise_error(ArgumentError)
6
+ expect { Aggregations::DateRange.new(nil) }.to raise_error(ArgumentError)
7
+ expect { Aggregations::DateRange.new('field_a').field(nil) }.to raise_error(ArgumentError)
8
+ end
9
+
10
+ it 'should fail if format not valid' do
11
+ expect { Aggregations::DateRange.new('field_a').format(123) }.to raise_error(ArgumentError)
12
+ expect { Aggregations::DateRange.new('field_a').format(nil) }.to raise_error(ArgumentError)
13
+ end
14
+
15
+ it 'should fail if keyed not valid' do
16
+ expect { Aggregations::DateRange.new('field_a').keyed(123) }.to raise_error(ArgumentError)
17
+ expect { Aggregations::DateRange.new('field_a').keyed(nil) }.to raise_error(ArgumentError)
18
+ expect { Aggregations::DateRange.new('field_a').keyed('fail') }.to raise_error(ArgumentError)
19
+ end
20
+
21
+ it 'should fail if range not valid' do
22
+ expect { Aggregations::DateRange.new('field_a').range(nil) }.to raise_error(ArgumentError)
23
+ expect { Aggregations::DateRange.new('field_a').range('now-10M/M', nil) }.to raise_error(ArgumentError)
24
+ expect { Aggregations::DateRange.new('field_a').range([1, 2]) }.to raise_error(ArgumentError)
25
+ end
26
+
27
+ it 'should chain create valid ES aggregation hash' do
28
+ date_range = Aggregations::DateRange.new('field_a').
29
+ format('MM-yyy').keyed(true).
30
+ range(from: 'now-10M/M', key: 'first').
31
+ range(from: 'now-20M/M', to: 'now-10M/M', key: 'second').
32
+ range(to: 'now-20M/M', key: 'third')
33
+ expect(date_range.to_hash).to eq(
34
+ date_range: {
35
+ field: 'field_a', format: 'MM-yyy', keyed: true,
36
+ ranges: [
37
+ { from: 'now-10M/M', key: 'first' },
38
+ { from: 'now-20M/M', to: 'now-10M/M', key: 'second' },
39
+ { to: 'now-20M/M', key: 'third' }
40
+ ]
41
+ }
42
+ )
43
+ end
44
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe ElasticsearchDslBuilder::DSL::Search::Aggregations::Filter do
4
+ it 'should fail if filter not valid' do
5
+ expect { Aggregations::Filter.new(nil) }.to raise_error(ArgumentError)
6
+ expect { Aggregations::Filter.new(123) }.to raise_error(ArgumentError)
7
+ expect { Aggregations::Filter.new(Queries::Exists.new('field')).filter(nil) }.to raise_error(ArgumentError)
8
+ end
9
+
10
+ it 'should chain create valid ES aggregation hash' do
11
+ filter = Aggregations::Filter.new(Queries::Exists.new('field_a'))
12
+ expect(filter.to_hash).to eq(filter: { exists: { field: 'field_a' } })
13
+ end
14
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe ElasticsearchDslBuilder::DSL::Search::Aggregations::Filters do
4
+ it 'should fail if filter not valid' do
5
+ expect { Aggregations::Filters.new.filter(nil) }.to raise_error(ArgumentError)
6
+ expect { Aggregations::Filters.new.filter(123) }.to raise_error(ArgumentError)
7
+ expect { Aggregations::Filters.new.filter(Queries::Exists.new('field'), 123) }.to raise_error(ArgumentError)
8
+ expect { Aggregations::Filters.new.filter(123, 'name') }.to raise_error(ArgumentError)
9
+ expect do
10
+ Aggregations::Filters.new.filter(Queries::Exists.new('field'), 'named').
11
+ filter(Queries::Exists.new('anon_filter'))
12
+ end.to raise_error(ArgumentError)
13
+ expect do
14
+ Aggregations::Filters.new.filter(Queries::Exists.new('anon_filter')).
15
+ filter(Queries::Exists.new('field'), 'named')
16
+ end.to raise_error(ArgumentError)
17
+ end
18
+
19
+ it 'should chain create valid ES aggregation hash' do
20
+ filters = Aggregations::Filters.new.
21
+ filter(Queries::Exists.new('field_a'), 'named_a').
22
+ filter(Queries::Exists.new('field_b'), 'named_b')
23
+ expect(filters.to_hash).to eq(
24
+ filters: { filters: { named_a: { exists: { field: 'field_a' } }, named_b: { exists: { field: 'field_b' } } } }
25
+ )
26
+
27
+ filters = Aggregations::Filters.new.
28
+ filter(Queries::Exists.new('field_a')).
29
+ filter(Queries::Exists.new('field_b'))
30
+ expect(filters.to_hash).to eq(filters: { filters: [{ exists: { field: 'field_a' } }, { exists: { field: 'field_b' } }] })
31
+ end
32
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe ElasticsearchDslBuilder::DSL::Search::Aggregations::GeohashGrid do
4
+ it 'should fail if field not valid' do
5
+ expect { Aggregations::GeohashGrid.new(nil) }.to raise_error(ArgumentError)
6
+ expect { Aggregations::GeohashGrid.new(123) }.to raise_error(ArgumentError)
7
+ expect { Aggregations::GeohashGrid.new('field').field(nil) }.to raise_error(ArgumentError)
8
+ end
9
+
10
+ it 'should fail if precision not valid' do
11
+ expect { Aggregations::GeohashGrid.new('field').precision(nil) }.to raise_error(ArgumentError)
12
+ expect { Aggregations::GeohashGrid.new('field').precision('fail') }.to raise_error(ArgumentError)
13
+ end
14
+
15
+ it 'should fail if size not valid' do
16
+ expect { Aggregations::GeohashGrid.new('field').size(nil) }.to raise_error(ArgumentError)
17
+ expect { Aggregations::GeohashGrid.new('field').size('fail') }.to raise_error(ArgumentError)
18
+ end
19
+
20
+ it 'should fail if shard_size not valid' do
21
+ expect { Aggregations::GeohashGrid.new('field').shard_size(nil) }.to raise_error(ArgumentError)
22
+ expect { Aggregations::GeohashGrid.new('field').shard_size('fail') }.to raise_error(ArgumentError)
23
+ end
24
+
25
+ it 'should chain create valid ES aggregation hash' do
26
+ geohash_grid = Aggregations::GeohashGrid.new('field').precision(1).size(2).shard_size(3)
27
+ expect(geohash_grid.to_hash).to eq(geohash_grid: { field: 'field', precision: 1, size: 2, shard_size: 3 })
28
+ end
29
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe ElasticsearchDslBuilder::DSL::Search::Aggregations::Range do
4
+ it 'should fail if field not valid' do
5
+ expect { Aggregations::Range.new.field(123) }.to raise_error(ArgumentError)
6
+ expect { Aggregations::Range.new.field(nil) }.to raise_error(ArgumentError)
7
+ expect { Aggregations::Range.new.field('field_a').field(nil) }.to raise_error(ArgumentError)
8
+ end
9
+
10
+ it 'should fail if script not valid' do
11
+ expect { Aggregations::Range.new.script(123) }.to raise_error(ArgumentError)
12
+ expect { Aggregations::Range.new.script(nil) }.to raise_error(ArgumentError)
13
+ expect { Aggregations::Range.new.script(Script.new.source('source')).script(nil) }.to raise_error(ArgumentError)
14
+ end
15
+
16
+ it 'should fail if keyed not valid' do
17
+ expect { Aggregations::Range.new.keyed(123) }.to raise_error(ArgumentError)
18
+ expect { Aggregations::Range.new.keyed(nil) }.to raise_error(ArgumentError)
19
+ end
20
+
21
+ it 'should fail if range not valid' do
22
+ expect { Aggregations::Range.new.range(nil) }.to raise_error(ArgumentError)
23
+ expect { Aggregations::Range.new.range(1, nil) }.to raise_error(ArgumentError)
24
+ expect { Aggregations::Range.new.range([1, 2]) }.to raise_error(ArgumentError)
25
+ end
26
+
27
+ it 'should chain create valid ES aggregation hash' do
28
+ range = Aggregations::Range.new.field('field_a').script(Script.new.source('source')).keyed(true).
29
+ range(from: 2, key: 'first').
30
+ range(from: 1, to: 2, key: 'second').
31
+ range(to: 1, key: 'third')
32
+ expect(range.to_hash).to eq(
33
+ range: {
34
+ field: 'field_a', script: { lang: 'painless', source: 'source' }, keyed: true,
35
+ ranges: [
36
+ { from: 2, key: 'first' },
37
+ { from: 1, to: 2, key: 'second' },
38
+ { to: 1, key: 'third' }
39
+ ]
40
+ }
41
+ )
42
+ end
43
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe ElasticsearchDslBuilder::DSL::Search::Aggregations::Stats do
4
+ it 'should fail if field not valid' do
5
+ expect { Aggregations::Stats.new.field(123) }.to raise_error(ArgumentError)
6
+ expect { Aggregations::Stats.new.field(nil) }.to raise_error(ArgumentError)
7
+ expect { Aggregations::Stats.new.field('field_a').field(nil) }.to raise_error(ArgumentError)
8
+ end
9
+
10
+ it 'should fail if script not valid' do
11
+ expect { Aggregations::Stats.new.script(123) }.to raise_error(ArgumentError)
12
+ expect { Aggregations::Stats.new.script(nil) }.to raise_error(ArgumentError)
13
+ expect { Aggregations::Stats.new.script(Script.new.source('source')).script(nil) }.to raise_error(ArgumentError)
14
+ end
15
+
16
+ it 'should chain create valid ES aggregation hash' do
17
+ stats = Aggregations::Stats.new.field('field_a').script(Script.new.source('source')).missing(1)
18
+ expect(stats.to_hash).to eq(stats: { field: 'field_a', script: { lang: 'painless', source: 'source' }, missing: 1 })
19
+ end
20
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe ElasticsearchDslBuilder::DSL::Search::Aggregations::SumBucket do
4
+ it 'should fail if buckets_path not valid' do
5
+ expect { Aggregations::SumBucket.new(123) }.to raise_error(ArgumentError)
6
+ expect { Aggregations::SumBucket.new(nil) }.to raise_error(ArgumentError)
7
+ expect { Aggregations::SumBucket.new('valid').buckets_path(nil) }.to raise_error(ArgumentError)
8
+ end
9
+
10
+ it 'should fail if gap_policy not valid' do
11
+ expect { Aggregations::SumBucket.new('valid').gap_policy(nil) }.to raise_error(ArgumentError)
12
+ expect { Aggregations::SumBucket.new('valid').gap_policy(123) }.to raise_error(ArgumentError)
13
+ end
14
+
15
+ it 'should fail if format not valid' do
16
+ expect { Aggregations::SumBucket.new('valid').format(nil) }.to raise_error(ArgumentError)
17
+ expect { Aggregations::SumBucket.new('valid').format(123) }.to raise_error(ArgumentError)
18
+ end
19
+
20
+ it 'should chain create valid ES aggregation hash' do
21
+ sum_bucket = Aggregations::SumBucket.new('buckets_path').gap_policy('skip').format('fmt')
22
+ expect(sum_bucket.to_hash).to eq(sum_bucket: { buckets_path: 'buckets_path', gap_policy: 'skip', format: 'fmt' })
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe ElasticsearchDslBuilder::DSL::Search::Aggregations::Sum do
4
+ it 'should fail if field not valid' do
5
+ expect { Aggregations::Sum.new.field(123) }.to raise_error(ArgumentError)
6
+ expect { Aggregations::Sum.new.field(nil) }.to raise_error(ArgumentError)
7
+ expect { Aggregations::Sum.new.field('field_a').field(nil) }.to raise_error(ArgumentError)
8
+ end
9
+
10
+ it 'should fail if script not valid' do
11
+ expect { Aggregations::Sum.new.script(123) }.to raise_error(ArgumentError)
12
+ expect { Aggregations::Sum.new.script(nil) }.to raise_error(ArgumentError)
13
+ expect { Aggregations::Sum.new.script(Script.new.source('source')).script(nil) }.to raise_error(ArgumentError)
14
+ end
15
+
16
+ it 'should chain create valid ES aggregation hash' do
17
+ sum = Aggregations::Sum.new.field('field_a').script(Script.new.source('source')).missing(1)
18
+ expect(sum.to_hash).to eq(sum: { field: 'field_a', script: { lang: 'painless', source: 'source' }, missing: 1 })
19
+ end
20
+ end
@@ -2,35 +2,50 @@ require 'spec_helper'
2
2
 
3
3
  describe ElasticsearchDslBuilder::DSL::Search::Aggregations::Terms do
4
4
  it 'should fail if field not valid' do
5
- expect { Aggregations::Terms.new(123) }.to raise_error(ArgumentError)
6
- expect { Aggregations::Terms.new(nil) }.to raise_error(ArgumentError)
7
- expect { Aggregations::Terms.new('field_a').field(nil) }.to raise_error(ArgumentError)
5
+ expect { Aggregations::Terms.new.field(123) }.to raise_error(ArgumentError)
6
+ expect { Aggregations::Terms.new.field(nil) }.to raise_error(ArgumentError)
7
+ end
8
+
9
+ it 'should fail if script is not valid' do
10
+ expect { Aggregations::Terms.new.script(Script.new.source('source').file('file')) }.to raise_error(ArgumentError)
11
+ expect { Aggregations::Terms.new.script(Script.new.source(123)) }.to raise_error(ArgumentError)
12
+ expect { Aggregations::Terms.new.script(Script.new.file(123)) }.to raise_error(ArgumentError)
13
+ expect { Aggregations::Terms.new.script(Script.new.source('source').lang(123)) }.to raise_error(ArgumentError)
14
+ expect { Aggregations::Terms.new.script(Script.new.source('source').params(123)) }.to raise_error(ArgumentError)
8
15
  end
9
16
 
10
17
  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)
18
+ expect { Aggregations::Terms.new.field('field_a').size('fail') }.to raise_error(ArgumentError)
19
+ expect { Aggregations::Terms.new.field('field_a').size(nil) }.to raise_error(ArgumentError)
13
20
  end
14
21
 
15
22
  it 'should fail if include not valid' do
16
- expect { Aggregations::Terms.new('field_a').include(nil) }.to raise_error(ArgumentError)
17
- expect { Aggregations::Terms.new('field_a').include({}) }.to raise_error(ArgumentError)
18
- expect { Aggregations::Terms.new('field_a').include([1, 2]) }.to raise_error(ArgumentError)
23
+ expect { Aggregations::Terms.new.field('field_a').include(nil) }.to raise_error(ArgumentError)
24
+ expect { Aggregations::Terms.new.field('field_a').include({}) }.to raise_error(ArgumentError)
25
+ expect { Aggregations::Terms.new.field('field_a').include([1, 2]) }.to raise_error(ArgumentError)
19
26
  end
20
27
 
21
28
  it 'should fail if exclude not valid' do
22
- expect { Aggregations::Terms.new('field_a').exclude(nil) }.to raise_error(ArgumentError)
23
- expect { Aggregations::Terms.new('field_a').exclude({}) }.to raise_error(ArgumentError)
24
- expect { Aggregations::Terms.new('field_a').exclude([1, 2]) }.to raise_error(ArgumentError)
29
+ expect { Aggregations::Terms.new.field('field_a').exclude(nil) }.to raise_error(ArgumentError)
30
+ expect { Aggregations::Terms.new.field('field_a').exclude({}) }.to raise_error(ArgumentError)
31
+ expect { Aggregations::Terms.new.field('field_a').exclude([1, 2]) }.to raise_error(ArgumentError)
25
32
  end
26
33
 
27
34
  it 'should chain create valid ES aggregation hash' do
28
- terms = Aggregations::Terms.new('field_a').
35
+ terms = Aggregations::Terms.new.
36
+ field('field_a').
37
+ script(Script.new.file('file').params(field: 'value')).
29
38
  size(5).
30
39
  include('*ball').exclude(['baseball', 'racquetball']).
31
- aggregation('nested_agg', Aggregations::Terms.new('field_b'))
40
+ aggregation('nested_agg', Aggregations::Terms.new.field('field_b'))
32
41
  expect(terms.to_hash).to eq(
33
- terms: { field: 'field_a', size: 5, include: '*ball', exclude: ['baseball', 'racquetball'] },
42
+ terms: {
43
+ field: 'field_a',
44
+ script: { file: 'file', params: { field: 'value' } },
45
+ size: 5,
46
+ include: '*ball',
47
+ exclude: ['baseball', 'racquetball']
48
+ },
34
49
  aggregations: { nested_agg: { terms: { field: 'field_b' } } }
35
50
  )
36
51
  end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe ElasticsearchDslBuilder::DSL::Search::Queries::GeoBoundingBox do
4
+ it 'should fail if field not a String or Symbol' do
5
+ expect { Queries::GeoBoundingBox.new(123) }.to raise_error(ArgumentError)
6
+ expect { Queries::GeoBoundingBox.new(nil) }.to raise_error(ArgumentError)
7
+ expect { Queries::GeoBoundingBox.new('field').field({}) }.to raise_error(ArgumentError)
8
+ end
9
+
10
+ it 'should fail if top_left arguments not Numeric' do
11
+ expect { Queries::GeoBoundingBox.new('field').top_left({}, nil) }.to raise_error(ArgumentError)
12
+ expect { Queries::GeoBoundingBox.new('field').top_left(1, nil) }.to raise_error(ArgumentError)
13
+ expect { Queries::GeoBoundingBox.new('field').top_left({}, 1) }.to raise_error(ArgumentError)
14
+ end
15
+
16
+ it 'should fail if bottom_right arguments not Numeric' do
17
+ expect { Queries::GeoBoundingBox.new('field').bottom_right({}, nil) }.to raise_error(ArgumentError)
18
+ expect { Queries::GeoBoundingBox.new('field').bottom_right(1, nil) }.to raise_error(ArgumentError)
19
+ expect { Queries::GeoBoundingBox.new('field').bottom_right({}, 1) }.to raise_error(ArgumentError)
20
+ end
21
+
22
+ it 'should fail if top_left_geohash argument not a String' do
23
+ expect { Queries::GeoBoundingBox.new('field').top_left_geohash({}) }.to raise_error(ArgumentError)
24
+ expect { Queries::GeoBoundingBox.new('field').top_left_geohash(nil) }.to raise_error(ArgumentError)
25
+ expect { Queries::GeoBoundingBox.new('field').top_left_geohash(1) }.to raise_error(ArgumentError)
26
+ end
27
+
28
+ it 'should fail if bottom_right_geohash argument not a String' do
29
+ expect { Queries::GeoBoundingBox.new('field').bottom_right_geohash({}) }.to raise_error(ArgumentError)
30
+ expect { Queries::GeoBoundingBox.new('field').bottom_right_geohash(nil) }.to raise_error(ArgumentError)
31
+ expect { Queries::GeoBoundingBox.new('field').bottom_right_geohash(1) }.to raise_error(ArgumentError)
32
+ end
33
+
34
+ it 'should fail if type argument not a String' do
35
+ expect { Queries::GeoBoundingBox.new('field').type({}) }.to raise_error(ArgumentError)
36
+ expect { Queries::GeoBoundingBox.new('field').type(nil) }.to raise_error(ArgumentError)
37
+ expect { Queries::GeoBoundingBox.new('field').type(1) }.to raise_error(ArgumentError)
38
+ end
39
+
40
+ it 'should chain create valid ES query hash' do
41
+ geo_bounding_box = Queries::GeoBoundingBox.new(:field_a).
42
+ top_left(1, 2).bottom_right(3, 4).type('indexed')
43
+ expect(geo_bounding_box.to_hash).to eq(
44
+ geo_bounding_box: { field_a: { top_left: { lat: 1, lon: 2 }, bottom_right: { lat: 3, lon: 4 } }, type: 'indexed' }
45
+ )
46
+
47
+ geo_bounding_box = Queries::GeoBoundingBox.new(:field_a).
48
+ top_left_geohash('dr5r9ydj2y73').bottom_right_geohash('dr5r9ydj2y73').type('indexed')
49
+ expect(geo_bounding_box.to_hash).to eq(
50
+ geo_bounding_box: { field_a: { top_left: 'dr5r9ydj2y73', bottom_right: 'dr5r9ydj2y73' }, type: 'indexed' }
51
+ )
52
+ end
53
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe ElasticsearchDslBuilder::DSL::Search::Script do
4
+ it 'should raise error if lang not valid' do
5
+ expect { Script.new.lang(123) }.to raise_error(ArgumentError)
6
+ expect { Script.new.lang(nil) }.to raise_error(ArgumentError)
7
+ end
8
+
9
+ it 'should raise error if source not valid' do
10
+ expect { Script.new.source(123) }.to raise_error(ArgumentError)
11
+ expect { Script.new.source(nil) }.to raise_error(ArgumentError)
12
+ end
13
+
14
+ it 'should raise error if file not valid' do
15
+ expect { Script.new.file(123) }.to raise_error(ArgumentError)
16
+ expect { Script.new.file(nil) }.to raise_error(ArgumentError)
17
+ end
18
+
19
+ it 'should raise error if params not valid' do
20
+ expect { Script.new.params(123) }.to raise_error(ArgumentError)
21
+ expect { Script.new.params(nil) }.to raise_error(ArgumentError)
22
+ end
23
+
24
+ it 'should raise error if both file and source are set' do
25
+ expect { Script.new.source('source').file('file') }.to raise_error(ArgumentError)
26
+ expect { Script.new.file('file').source('source') }.to raise_error(ArgumentError)
27
+ end
28
+
29
+ it 'should chain build valid ES script' do
30
+ script = Script.new.lang('painless').source('source').params(field: 'value')
31
+ expect(script.to_hash).to eq(lang: 'painless', source: 'source', params: { field: 'value' })
32
+
33
+ script = Script.new.lang('painless').file('file').params(field: 'value')
34
+ expect(script.to_hash).to eq(file: 'file', params: { field: 'value' })
35
+ end
36
+ end
@@ -53,7 +53,7 @@ describe ElasticsearchDslBuilder::DSL::Search::Search do
53
53
  search_after(2, 1).
54
54
  include_fields('id', 'content').
55
55
  exclude_fields('no_show').
56
- aggregation('my_agg', Aggregations::Terms.new('field_a'))
56
+ aggregation('my_agg', Aggregations::Terms.new.field('field_a'))
57
57
 
58
58
  expect(search.to_hash).to eq(
59
59
  query: { bool: {} },
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.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marvin Guerra
@@ -85,11 +85,23 @@ 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/cardinality.rb
89
+ - lib/elasticsearch_dsl_builder/dsl/search/aggregations/children.rb
90
+ - lib/elasticsearch_dsl_builder/dsl/search/aggregations/date_histogram.rb
91
+ - lib/elasticsearch_dsl_builder/dsl/search/aggregations/date_range.rb
92
+ - lib/elasticsearch_dsl_builder/dsl/search/aggregations/filter.rb
93
+ - lib/elasticsearch_dsl_builder/dsl/search/aggregations/filters.rb
94
+ - lib/elasticsearch_dsl_builder/dsl/search/aggregations/geohash_grid.rb
88
95
  - lib/elasticsearch_dsl_builder/dsl/search/aggregations/nested.rb
96
+ - lib/elasticsearch_dsl_builder/dsl/search/aggregations/range.rb
97
+ - lib/elasticsearch_dsl_builder/dsl/search/aggregations/stats.rb
98
+ - lib/elasticsearch_dsl_builder/dsl/search/aggregations/sum.rb
99
+ - lib/elasticsearch_dsl_builder/dsl/search/aggregations/sum_bucket.rb
89
100
  - lib/elasticsearch_dsl_builder/dsl/search/aggregations/terms.rb
90
101
  - lib/elasticsearch_dsl_builder/dsl/search/queries/bool.rb
91
102
  - lib/elasticsearch_dsl_builder/dsl/search/queries/exists.rb
92
103
  - lib/elasticsearch_dsl_builder/dsl/search/queries/function_score.rb
104
+ - lib/elasticsearch_dsl_builder/dsl/search/queries/geo_bounding_box.rb
93
105
  - lib/elasticsearch_dsl_builder/dsl/search/queries/has_child.rb
94
106
  - lib/elasticsearch_dsl_builder/dsl/search/queries/has_parent.rb
95
107
  - lib/elasticsearch_dsl_builder/dsl/search/queries/match.rb
@@ -100,14 +112,27 @@ files:
100
112
  - lib/elasticsearch_dsl_builder/dsl/search/queries/terms.rb
101
113
  - lib/elasticsearch_dsl_builder/dsl/search/queries/wildcard.rb
102
114
  - lib/elasticsearch_dsl_builder/dsl/search/query.rb
115
+ - lib/elasticsearch_dsl_builder/dsl/search/script.rb
103
116
  - lib/elasticsearch_dsl_builder/dsl/search/sort.rb
104
117
  - lib/elasticsearch_dsl_builder/dsl/version.rb
105
118
  - lib/elasticsearch_dsl_builder/exceptions.rb
119
+ - spec/lib/dsl/search/aggregations/cardinality_spec.rb
120
+ - spec/lib/dsl/search/aggregations/children_spec.rb
121
+ - spec/lib/dsl/search/aggregations/date_histogram_spec.rb
122
+ - spec/lib/dsl/search/aggregations/date_range_spec.rb
123
+ - spec/lib/dsl/search/aggregations/filter_spec.rb
124
+ - spec/lib/dsl/search/aggregations/filters_spec.rb
125
+ - spec/lib/dsl/search/aggregations/geohash_grid_spec.rb
106
126
  - spec/lib/dsl/search/aggregations/nested_spec.rb
127
+ - spec/lib/dsl/search/aggregations/range_spec.rb
128
+ - spec/lib/dsl/search/aggregations/stats_spec.rb
129
+ - spec/lib/dsl/search/aggregations/sum_bucket_spec.rb
130
+ - spec/lib/dsl/search/aggregations/sum_spec.rb
107
131
  - spec/lib/dsl/search/aggregations/terms_spec.rb
108
132
  - spec/lib/dsl/search/queries/bool_spec.rb
109
133
  - spec/lib/dsl/search/queries/exists_spec.rb
110
134
  - spec/lib/dsl/search/queries/function_score_spec.rb
135
+ - spec/lib/dsl/search/queries/geo_bounding_box_spec.rb
111
136
  - spec/lib/dsl/search/queries/has_child_spec.rb
112
137
  - spec/lib/dsl/search/queries/has_parent_spec.rb
113
138
  - spec/lib/dsl/search/queries/match_spec.rb
@@ -117,6 +142,7 @@ files:
117
142
  - spec/lib/dsl/search/queries/term_spec.rb
118
143
  - spec/lib/dsl/search/queries/terms_spec.rb
119
144
  - spec/lib/dsl/search/queries/wildcard_spec.rb
145
+ - spec/lib/dsl/search/script_spec.rb
120
146
  - spec/lib/dsl/search/sort_spec.rb
121
147
  - spec/lib/dsl/search_spec.rb
122
148
  - spec/lib/dsl_spec.rb
@@ -148,11 +174,23 @@ specification_version: 4
148
174
  summary: Library utilizing builder pattern providing Ruby API for the Elasticsearch
149
175
  Query DSL
150
176
  test_files:
177
+ - spec/lib/dsl/search/aggregations/cardinality_spec.rb
178
+ - spec/lib/dsl/search/aggregations/children_spec.rb
179
+ - spec/lib/dsl/search/aggregations/date_histogram_spec.rb
180
+ - spec/lib/dsl/search/aggregations/date_range_spec.rb
181
+ - spec/lib/dsl/search/aggregations/filter_spec.rb
182
+ - spec/lib/dsl/search/aggregations/filters_spec.rb
183
+ - spec/lib/dsl/search/aggregations/geohash_grid_spec.rb
151
184
  - spec/lib/dsl/search/aggregations/nested_spec.rb
185
+ - spec/lib/dsl/search/aggregations/range_spec.rb
186
+ - spec/lib/dsl/search/aggregations/stats_spec.rb
187
+ - spec/lib/dsl/search/aggregations/sum_bucket_spec.rb
188
+ - spec/lib/dsl/search/aggregations/sum_spec.rb
152
189
  - spec/lib/dsl/search/aggregations/terms_spec.rb
153
190
  - spec/lib/dsl/search/queries/bool_spec.rb
154
191
  - spec/lib/dsl/search/queries/exists_spec.rb
155
192
  - spec/lib/dsl/search/queries/function_score_spec.rb
193
+ - spec/lib/dsl/search/queries/geo_bounding_box_spec.rb
156
194
  - spec/lib/dsl/search/queries/has_child_spec.rb
157
195
  - spec/lib/dsl/search/queries/has_parent_spec.rb
158
196
  - spec/lib/dsl/search/queries/match_spec.rb
@@ -162,6 +200,7 @@ test_files:
162
200
  - spec/lib/dsl/search/queries/term_spec.rb
163
201
  - spec/lib/dsl/search/queries/terms_spec.rb
164
202
  - spec/lib/dsl/search/queries/wildcard_spec.rb
203
+ - spec/lib/dsl/search/script_spec.rb
165
204
  - spec/lib/dsl/search/sort_spec.rb
166
205
  - spec/lib/dsl/search_spec.rb
167
206
  - spec/lib/dsl_spec.rb