elasticated 2.5.5 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +35 -2
  3. data/Rakefile +52 -1
  4. data/elasticated.gemspec +3 -1
  5. data/lib/elasticated.rb +20 -24
  6. data/lib/elasticated/aggregation.rb +3 -6
  7. data/lib/elasticated/aggregations/date_histogram_aggregation.rb +6 -1
  8. data/lib/elasticated/aggregations/filter_aggregation.rb +8 -12
  9. data/lib/elasticated/aggregations/filter_aggregation_evaluator.rb +1 -1
  10. data/lib/elasticated/aggregations/group_aggregation.rb +14 -11
  11. data/lib/elasticated/aggregations/range_aggregation.rb +10 -11
  12. data/lib/elasticated/aggregations/range_aggregation_evaluator.rb +1 -1
  13. data/lib/elasticated/aggregations/ranges_builder.rb +2 -2
  14. data/lib/elasticated/aggregations/safe_date_histogram_aggregation.rb +7 -2
  15. data/lib/elasticated/aggregations/subaggregated.rb +1 -1
  16. data/lib/elasticated/boolean_clause.rb +4 -3
  17. data/lib/elasticated/bulk_actions/create_action.rb +14 -0
  18. data/lib/elasticated/bulk_actions/delete_action.rb +30 -0
  19. data/lib/elasticated/bulk_actions/index_action.rb +35 -0
  20. data/lib/elasticated/bulk_actions/standard_action.rb +22 -0
  21. data/lib/elasticated/bulk_actions/update_action.rb +44 -0
  22. data/lib/elasticated/bulk_actions/upsert_action.rb +14 -0
  23. data/lib/elasticated/bulk_request.rb +58 -0
  24. data/lib/elasticated/bulk_request/response.rb +32 -0
  25. data/lib/elasticated/bulk_request/response_item.rb +39 -0
  26. data/lib/elasticated/client.rb +27 -3
  27. data/lib/elasticated/conditions/custom_condition.rb +3 -3
  28. data/lib/elasticated/conditions/range_condition.rb +5 -2
  29. data/lib/elasticated/conditions/script_condition.rb +3 -3
  30. data/lib/elasticated/conditions/standard_condition.rb +4 -5
  31. data/lib/elasticated/conditions/term_condition.rb +22 -0
  32. data/lib/elasticated/conditions/terms_condition.rb +2 -2
  33. data/lib/elasticated/conditions_builder.rb +19 -4
  34. data/lib/elasticated/delimiters/date_field_delimiter.rb +21 -12
  35. data/lib/elasticated/delimiters/standard_field_delimiter.rb +18 -2
  36. data/lib/elasticated/delimiters/term_field_delimiter.rb +6 -5
  37. data/lib/elasticated/document.rb +20 -1
  38. data/lib/elasticated/enum.rb +17 -0
  39. data/lib/elasticated/index_selector.rb +26 -25
  40. data/lib/elasticated/mapping.rb +2 -4
  41. data/lib/elasticated/mapping/builder.rb +3 -2
  42. data/lib/elasticated/mapping/fields_builder.rb +13 -9
  43. data/lib/elasticated/mapping/object_builder.rb +38 -4
  44. data/lib/elasticated/mapping/type_builder.rb +3 -5
  45. data/lib/elasticated/mixins/block_evaluation.rb +17 -0
  46. data/lib/elasticated/mixins/clonable.rb +60 -0
  47. data/lib/elasticated/mixins/configurable.rb +22 -0
  48. data/lib/elasticated/mixins/inspectionable.rb +16 -0
  49. data/lib/elasticated/partitioned_repository.rb +24 -18
  50. data/lib/elasticated/query.rb +27 -21
  51. data/lib/elasticated/query_aggregations.rb +5 -7
  52. data/lib/elasticated/query_conditions.rb +6 -3
  53. data/lib/elasticated/quick.rb +7 -0
  54. data/lib/elasticated/repository.rb +184 -40
  55. data/lib/elasticated/repository/intelligent_search.rb +3 -3
  56. data/lib/elasticated/repository/normal_search.rb +2 -2
  57. data/lib/elasticated/repository/resumable_search.rb +5 -5
  58. data/lib/elasticated/repository/scan_scroll_search.rb +4 -4
  59. data/lib/elasticated/repository/scroll_search.rb +3 -3
  60. data/lib/elasticated/repository/search.rb +7 -0
  61. data/lib/elasticated/repository/single_page_search.rb +1 -1
  62. data/lib/elasticated/results.rb +14 -0
  63. data/lib/version.rb +18 -25
  64. data/spec/aggregation_spec.rb +95 -16
  65. data/spec/bulk_request_spec.rb +158 -0
  66. data/spec/date_field_delimiter_spec.rb +50 -6
  67. data/spec/document_spec.rb +1 -5
  68. data/spec/integration_spec.rb +7 -7
  69. data/spec/mapping_spec.rb +128 -8
  70. data/spec/partitioned_repository_spec.rb +218 -0
  71. data/spec/query_conditions_spec.rb +98 -45
  72. data/spec/query_spec.rb +21 -28
  73. data/spec/repository_spec.rb +245 -0
  74. data/spec/results_spec.rb +0 -4
  75. data/spec/sample_responses/elasticsearch_bulk_response_1.json +35 -0
  76. data/spec/sample_responses/elasticsearch_bulk_response_2.json +20 -0
  77. data/spec/sample_responses/elasticsearch_count_1.json +8 -0
  78. data/spec/sample_responses/elasticsearch_count_2.json +8 -0
  79. data/spec/sample_responses/elasticsearch_get_response_1.json +10 -0
  80. data/spec/sample_responses/elasticsearch_get_response_2.json +6 -0
  81. data/spec/{elasticsearch_hit_1.json → sample_responses/elasticsearch_hit_1.json} +0 -0
  82. data/spec/sample_responses/elasticsearch_mget_response_1.json +25 -0
  83. data/spec/{elasticsearch_response_1.json → sample_responses/elasticsearch_response_1.json} +0 -0
  84. data/spec/{elasticsearch_response_2.json → sample_responses/elasticsearch_response_2.json} +0 -0
  85. data/spec/{elasticsearch_top_hits_response.json → sample_responses/elasticsearch_top_hits_response.json} +0 -0
  86. data/spec/spec_helper.rb +47 -0
  87. data/spec/spec_helper/fake_index_selector.rb +27 -0
  88. data/spec/term_field_delimiter_spec.rb +8 -8
  89. metadata +80 -26
  90. data/lib/elasticated/block_evaluation.rb +0 -15
  91. data/lib/elasticated/clonable.rb +0 -58
  92. data/lib/elasticated/configurable.rb +0 -20
  93. data/lib/elasticated/date_delimiter_factory.rb +0 -123
  94. data/lib/elasticated/delimiter_visitor.rb +0 -53
  95. data/lib/elasticated/inspectionable.rb +0 -9
  96. data/lib/elasticated/strategy_params_for_query_service.rb +0 -14
  97. data/lib/elasticated/term_delimiter_factory.rb +0 -73
  98. data/spec/delimiter_factory_spec.rb +0 -399
  99. data/spec/strategy_params_for_query_service_spec.rb +0 -387
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 34aaec873567c3de5edbd386329dd360e23367b1
4
- data.tar.gz: d6f933aabaef089340d584edc22ab152438ef726
3
+ metadata.gz: eefc3eab5d4fd7000cb959f921e9d1622769c7df
4
+ data.tar.gz: 4cb4baa5ad341834938c175bffdad61669b63695
5
5
  SHA512:
6
- metadata.gz: 64db33fc483ffa746f8b94cfd80e77d721e2c7ad261b44ee5f5c98f271f926008bed2fa4b3bb53d040bc3d90970d667e46db86a3583b68fb76bae6e30178909b
7
- data.tar.gz: c9127b2363ab80dba4fb306e3cc43990b1384861bf04d492dd9bf43b35a3c7b45437acdd74768fc2a0631bb8b6ae13cdc9639c0dce4a7b2469209e92a738e1d7
6
+ metadata.gz: 62b3e29e6aa0e3c6406d65b7ecb041ac7ab4762f92007e6f63f2f830527b41df33e619f0078c886701b465b27ada8f390dec6963eb9d35522e56ba1dcd9adff5
7
+ data.tar.gz: 57691483ddb1372257bf5bba74da566d8e7a6259ebc3c59f107b77e8a8b4780b64bce4d30d5926a34477e7072110d80a684dc37e35e4f09f423abad66783975c
data/README.md CHANGED
@@ -50,7 +50,7 @@ repository.delete_by query
50
50
  repository.exists? query
51
51
  ```
52
52
 
53
- **HOW TO** build a document, index or update it
53
+ **HOW TO** build a document and index it
54
54
  ```ruby
55
55
  document = Document.create do |doc|
56
56
  doc.id = 'my_unique_id'
@@ -60,7 +60,39 @@ document = Document.create do |doc|
60
60
  end
61
61
  repository = Repository.new
62
62
  repository.index_document document
63
- repository.update_document document
63
+ ```
64
+
65
+ **HOW TO** build a document and (partially) update it
66
+ ```ruby
67
+ repository = Repository.new
68
+ repository.update_document 'my_unique_id', type: 'mytype', index: 'myindex', source: { new_field: 'New data' }
69
+ ```
70
+
71
+ **HOW TO** get a document (or multiple documents) by id
72
+ ```ruby
73
+ repository = Repository.new
74
+ document = repository.get_document 'my_unique_id', type: 'mytype', index: 'myindex'
75
+ documents = repository.get_documents ['id1', 'id2', 'id3'], type: 'mytype', index: 'myindex'
76
+ ```
77
+
78
+ **HOW TO** delete a document by id
79
+ ```ruby
80
+ repository = Repository.new
81
+ repository.delete_document 'my_unique_id', type: 'mytype', index: 'myindex'
82
+ ```
83
+
84
+ **HOW TO** execute a bulk request
85
+ ```ruby
86
+ repository = Repository.new
87
+ document = Document.create id: 'my_id', type: 'my_type', index: 'my_index', source: { name: 'Pablo' }
88
+ bulk_request = repository.prepare_bulk do
89
+ index_document d
90
+ delete_document 'my_id', type: 'my_type', index: 'my_index'
91
+ upsert_document 'my_id', type: 'my_type', index: 'my_index', source: { name: 'Santiago' }
92
+ update_document 'my_id', type: 'my_type', index: 'my_index', source: { age: 24 }
93
+ create_document d # this one will return error individually
94
+ end
95
+ response = repository.execute_bulk bulk_request
64
96
  ```
65
97
 
66
98
  **HOW TO** start a *resumable* scroll
@@ -103,6 +135,7 @@ mapping = Elasticated::Mapping.build do
103
135
  end
104
136
  end
105
137
  end
138
+ mapping.to_h
106
139
  ```
107
140
 
108
141
  **HOW TO** configure the gem
data/Rakefile CHANGED
@@ -3,4 +3,55 @@ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task :default => :spec
7
+
8
+ namespace :elasticsearch do
9
+
10
+ require 'elasticsearch'
11
+ require 'elasticsearch/extensions/test/cluster'
12
+ require 'socket'
13
+
14
+ task :prepare_env do
15
+ hostname = Socket.gethostname rescue Time.now.to_i
16
+ ENV['TEST_CLUSTER_COMMAND'] ||= '/usr/share/elasticsearch/bin/elasticsearch'
17
+ ENV['TEST_CLUSTER_NAME'] ||= "elasticated-#{hostname}"
18
+ ENV['TEST_CLUSTER_PORT'] ||= '9250'
19
+ ENV['TEST_CLUSTER_NODES'] ||= '1'
20
+ # ENV['TEST_CLUSTER_NODE_NAME'] ||= 'node'
21
+ # ENV['TEST_CLUSTER_DATA'] ||= '/tmp/elasticsearch_test'
22
+ # ENV['TEST_CLUSTER_TMP'] ||= '/tmp'
23
+ # ENV['TEST_CLUSTER_LOGS'] ||= '/tmp/log/elasticsearch'
24
+ # ENV['TEST_CLUSTER_PARAMS'] ||= ''
25
+ # ENV['TEST_CLUSTER_MULTICAST'] ||= 'true'
26
+ # ENV['TEST_CLUSTER_TIMEOUT'] ||= 30
27
+ # ENV['TEST_CLUSTER_NETWORK_HOST'] ||= __default_network_host
28
+ # ENV['QUIET'] ||= 'true'
29
+ end
30
+
31
+ desc 'Start Elasticsearch test cluster (See TEST_CLUSTER_* env vars)'
32
+ task start: :prepare_env do
33
+ Elasticsearch::Extensions::Test::Cluster.start unless Elasticsearch::Extensions::Test::Cluster.running?
34
+ end
35
+
36
+ desc 'Stop Elasticsearch test cluster'
37
+ task stop: :prepare_env do
38
+ Elasticsearch::Extensions::Test::Cluster.stop if Elasticsearch::Extensions::Test::Cluster.running?
39
+ end
40
+
41
+ desc 'Restart Elasticsearch test cluster'
42
+ task restart: :prepare_env do
43
+ Rake::Task['elasticsearch:stop'].invoke
44
+ Rake::Task['elasticsearch:start'].invoke
45
+ end
46
+
47
+ desc 'Show Elasticsearch test cluster status'
48
+ task status: :prepare_env do
49
+ puts Elasticsearch::Extensions::Test::Cluster.running? ? 'Running' : 'Stopped'
50
+ end
51
+
52
+ desc 'Show Elasticsearch test cluster environment variables'
53
+ task env: :prepare_env do
54
+ ENV.select { |k,v| k.start_with? 'TEST_CLUSTER_' }.each { |k,v| puts "#{k}=#{v}" }
55
+ end
56
+
57
+ end
data/elasticated.gemspec CHANGED
@@ -19,9 +19,11 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_development_dependency 'bundler', '~> 1.5'
22
- spec.add_development_dependency 'rspec', '3.0.0'
22
+ spec.add_development_dependency 'rspec', '~> 3.0'
23
23
  spec.add_development_dependency 'rake'
24
24
  spec.add_development_dependency 'pry-byebug'
25
+ spec.add_development_dependency 'simplecov'
26
+ spec.add_development_dependency 'elasticsearch-extensions'
25
27
 
26
28
  spec.add_runtime_dependency 'elasticsearch'
27
29
  spec.add_runtime_dependency 'hash_ext', '~> 0.1.1'
data/lib/elasticated.rb CHANGED
@@ -7,15 +7,19 @@ require_relative 'elasticated/loggers/silent_logger'
7
7
  require_relative 'elasticated/loggers/default_logger'
8
8
 
9
9
  require_relative 'elasticated/helpers'
10
- require_relative 'elasticated/block_evaluation'
11
- require_relative 'elasticated/clonable'
12
- require_relative 'elasticated/inspectionable'
10
+ require_relative 'elasticated/enum'
11
+
12
+ require_relative 'elasticated/mixins/block_evaluation'
13
+ require_relative 'elasticated/mixins/clonable'
14
+ require_relative 'elasticated/mixins/inspectionable'
15
+ require_relative 'elasticated/mixins/configurable'
16
+
13
17
  require_relative 'elasticated/configuration'
14
- require_relative 'elasticated/configurable'
15
18
 
16
19
  # query conditions
17
20
 
18
21
  require_relative 'elasticated/conditions/standard_condition'
22
+ require_relative 'elasticated/conditions/term_condition'
19
23
  require_relative 'elasticated/conditions/terms_condition'
20
24
  require_relative 'elasticated/conditions/wildcard_condition'
21
25
  require_relative 'elasticated/conditions/exists_condition'
@@ -30,10 +34,6 @@ require_relative 'elasticated/conditions/custom_condition'
30
34
  require_relative 'elasticated/delimiters/standard_field_delimiter'
31
35
  require_relative 'elasticated/delimiters/term_field_delimiter'
32
36
  require_relative 'elasticated/delimiters/date_field_delimiter'
33
- require_relative 'elasticated/term_delimiter_factory'
34
- require_relative 'elasticated/date_delimiter_factory'
35
- require_relative 'elasticated/delimiter_visitor'
36
- require_relative 'elasticated/strategy_params_for_query_service'
37
37
 
38
38
  # query components
39
39
 
@@ -83,6 +83,18 @@ require_relative 'elasticated/aggregations/top_hits_aggregation'
83
83
 
84
84
  require_relative 'elasticated/aggregations/custom_aggregation'
85
85
 
86
+ # bulk requests
87
+
88
+ require_relative 'elasticated/bulk_request'
89
+ require_relative 'elasticated/bulk_request/response'
90
+ require_relative 'elasticated/bulk_request/response_item'
91
+ require_relative 'elasticated/bulk_actions/standard_action'
92
+ require_relative 'elasticated/bulk_actions/index_action'
93
+ require_relative 'elasticated/bulk_actions/create_action'
94
+ require_relative 'elasticated/bulk_actions/update_action'
95
+ require_relative 'elasticated/bulk_actions/upsert_action'
96
+ require_relative 'elasticated/bulk_actions/delete_action'
97
+
86
98
  # repository
87
99
 
88
100
  require_relative 'elasticated/document'
@@ -116,20 +128,4 @@ module Elasticated
116
128
  block.call Configuration
117
129
  end
118
130
 
119
- def self.date_delimiter_factory
120
- @date_delimiter_factory ||= DateDelimiterFactory.new
121
- end
122
-
123
- def self.term_delimiter_factory
124
- @term_delimiter_factory ||= TermDelimiterFactory.new
125
- end
126
-
127
- def self.delimiter_visitor
128
- @delimiter_visitor ||= DelimiterVisitor.new
129
- end
130
-
131
- def self.strategy_params_for_query_service
132
- @strategy_params_for_query_service ||= StrategyParamsForQueryService.new
133
- end
134
-
135
131
  end
@@ -6,8 +6,9 @@ module Elasticated
6
6
  # child must implement 'build'
7
7
  # child must implement 'parse(response)'
8
8
 
9
- include BlockEvaluation
10
- include Clonable
9
+ include Mixins::Clonable
10
+ include Mixins::BlockEvaluation
11
+ include Mixins::Inspectionable
11
12
 
12
13
  attr_accessor :field, :alias_name, :extra_params
13
14
 
@@ -32,9 +33,5 @@ module Elasticated
32
33
  end
33
34
  end
34
35
 
35
- def accept_visitor(visitor)
36
- visitor.visit_aggregation(self)
37
- end
38
-
39
36
  end
40
37
  end
@@ -2,16 +2,21 @@ module Elasticated
2
2
  class DateHistogramAggregation < HistogramAggregation
3
3
  include Subaggregated
4
4
 
5
- attr_accessor :format
5
+ attr_accessor :format, :offset
6
6
 
7
7
  def initialize(field, opts={}, &block)
8
8
  self.format = opts.delete(:format) || 'yyyy-MM-dd'
9
9
  interval = opts.delete(:interval) || 'day'
10
+ self.offset = opts.delete(:offset)
10
11
  super field, interval, opts, &block
11
12
  end
12
13
 
13
14
  def build
14
15
  terms = { field: field, interval: interval, format: format }
16
+ if offset # '1.4 style'
17
+ terms.merge! pre_offset: offset
18
+ terms.merge! post_offset: offset
19
+ end
15
20
  terms.merge! extra_params
16
21
  aggregation_struct = { date_histogram: terms }
17
22
  aggregation_struct.merge! build_subaggregations
@@ -2,13 +2,13 @@ module Elasticated
2
2
  class FilterAggregation < Aggregation
3
3
  include Subaggregated
4
4
 
5
- attr_accessor :_evaluator, :_filter_name, :compact, :include_count
5
+ attr_accessor :_evaluator, :_filter_name, :compact
6
6
 
7
7
  def initialize(filter_name, *args, &block)
8
8
  self._filter_name = filter_name
9
9
  super
10
10
  self.compact = extra_params.delete(:compact) { false }
11
- self.include_count = extra_params.delete(:include_count) { true }
11
+ raise "The 'include_count' parameter was removed in filter aggregations" if extra_params.has_key? :include_count
12
12
  initialize_subaggregations FilterAggregationEvaluator.new, &block
13
13
  end
14
14
 
@@ -26,19 +26,15 @@ module Elasticated
26
26
 
27
27
  def parse(response)
28
28
  count = response['doc_count']
29
-
30
- if _subaggregations.empty?
31
- compact ? count : { 'count' => count }
29
+ if compact && _subaggregations.empty?
30
+ count
32
31
  else
33
- parse_subaggregations(response).tap do |h|
34
- h['count'] = count if include_count
35
- end
32
+ raise "Compact is not a valid parameter on a subaggregated 'filter' aggregation" if compact
33
+ body = { 'count' => count }
34
+ body.merge! parse_subaggregations(response)
35
+ body
36
36
  end
37
37
  end
38
38
 
39
- def accept_visitor(visitor)
40
- visitor.visit_filter_aggregation(self)
41
- end
42
-
43
39
  end
44
40
  end
@@ -1,7 +1,7 @@
1
1
  module Elasticated
2
2
  class FilterAggregationEvaluator < QueryAggregations
3
3
 
4
- include BlockEvaluation
4
+ include Mixins::BlockEvaluation
5
5
 
6
6
  attr_accessor :_conditions
7
7
 
@@ -2,12 +2,13 @@ module Elasticated
2
2
  class GroupAggregation < TermsAggregation
3
3
  include Subaggregated
4
4
 
5
- attr_accessor :compact, :include_count
5
+ attr_accessor :compact, :key_as_string
6
6
 
7
7
  def initialize(field, *args, &block)
8
8
  super
9
9
  self.compact = extra_params.delete(:compact) { false }
10
- self.include_count = extra_params.delete(:include_count) { true }
10
+ self.key_as_string = extra_params.delete(:key_as_string) { false }
11
+ raise "The 'include_count' parameter was removed in group aggregations" if extra_params.has_key? :include_count
11
12
  initialize_subaggregations &block
12
13
  end
13
14
 
@@ -21,16 +22,18 @@ module Elasticated
21
22
 
22
23
  def parse(response)
23
24
  response['buckets'].each_with_object({}) do |bucket, hash|
25
+ key = bucket['key']
24
26
  count = bucket['doc_count']
25
-
26
- hash[bucket['key']] =
27
- if _subaggregations.empty?
28
- compact ? count : { 'count' => count }
29
- else
30
- parse_subaggregations(bucket).tap do |h|
31
- h['count'] = count if include_count
32
- end
33
- end
27
+ key_as_str = bucket['key_as_string']
28
+ hash[key] = if compact && _subaggregations.empty?
29
+ count
30
+ else
31
+ raise "Compact is not a valid parameter on a subaggregated 'terms' aggregation" if compact
32
+ body = { 'count' => count }
33
+ body.merge! 'key_as_string' => key_as_str if key_as_string
34
+ body.merge! parse_subaggregations bucket
35
+ body
36
+ end
34
37
  end
35
38
  end
36
39
 
@@ -2,12 +2,12 @@ module Elasticated
2
2
  class RangeAggregation < Aggregation
3
3
  include Subaggregated
4
4
 
5
- attr_accessor :_conditions, :compact, :include_count
5
+ attr_accessor :_conditions, :compact
6
6
 
7
7
  def initialize(field, *args, &block)
8
8
  super
9
9
  self.compact = extra_params.delete(:compact) { false }
10
- self.include_count = extra_params.delete(:include_count) { true }
10
+ raise "The 'include_count' parameter was removed in range aggregations" if extra_params.has_key? :include_count
11
11
  initialize_subaggregations RangeAggregationEvaluator.new, &block
12
12
  end
13
13
 
@@ -28,15 +28,14 @@ module Elasticated
28
28
  def parse(response)
29
29
  response['buckets'].each_with_object({}) do |(key_name, values), hash|
30
30
  count = values['doc_count']
31
-
32
- hash[key_name] =
33
- if _subaggregations.empty?
34
- compact ? count : { 'count' => count }
35
- else
36
- parse_subaggregations(values).tap do |h|
37
- h['count'] = count if include_count
38
- end
39
- end
31
+ hash[key_name] = if compact && _subaggregations.empty?
32
+ count
33
+ else
34
+ raise "Compact is not a valid parameter on a subaggregated 'range' aggregation" if compact
35
+ body = { 'count' => count }
36
+ body.merge! parse_subaggregations(values)
37
+ body
38
+ end
40
39
  end
41
40
  end
42
41
 
@@ -1,7 +1,7 @@
1
1
  module Elasticated
2
2
  class RangeAggregationEvaluator < QueryAggregations
3
3
 
4
- include BlockEvaluation
4
+ include Mixins::BlockEvaluation
5
5
 
6
6
  attr_accessor :_ranges_builder
7
7
 
@@ -1,8 +1,8 @@
1
1
  module Elasticated
2
2
  class RangesBuilder
3
3
 
4
- include Clonable
5
- include BlockEvaluation
4
+ include Mixins::Clonable
5
+ include Mixins::BlockEvaluation
6
6
 
7
7
  attr_accessor :_ranges
8
8
 
@@ -4,9 +4,10 @@ module Elasticated
4
4
 
5
5
  DEFAULT_INTERVAL = '1d'
6
6
 
7
- attr_accessor :time_zone, :points, :compact, :include_count
7
+ attr_accessor :offset, :time_zone, :points, :compact, :include_count
8
8
 
9
9
  def initialize(field, opts={}, &block)
10
+ self.offset = opts.delete(:offset)
10
11
  self.time_zone = opts.delete(:time_zone)
11
12
  self.points = opts.fetch(:points)
12
13
  opts.delete(:points)
@@ -18,6 +19,10 @@ module Elasticated
18
19
 
19
20
  def build
20
21
  terms = { field: field, interval: safe_interval.to_s }
22
+ if offset # '1.4 style'
23
+ terms.merge! pre_offset: offset
24
+ terms.merge! post_offset: offset
25
+ end
21
26
  if time_zone
22
27
  terms.merge! time_zone: time_zone
23
28
  end
@@ -43,7 +48,7 @@ module Elasticated
43
48
  else
44
49
  parsed_subaggregations = parse_subaggregations(bucket)
45
50
  hash[key] = value_for(parsed_subaggregations, hash, key).tap do |h|
46
- h['count'] = count if include_count
51
+ h['count'] = count #if include_count
47
52
  end
48
53
  end
49
54
  end