elasticated 2.5.5 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +35 -2
- data/Rakefile +52 -1
- data/elasticated.gemspec +3 -1
- data/lib/elasticated.rb +20 -24
- data/lib/elasticated/aggregation.rb +3 -6
- data/lib/elasticated/aggregations/date_histogram_aggregation.rb +6 -1
- data/lib/elasticated/aggregations/filter_aggregation.rb +8 -12
- data/lib/elasticated/aggregations/filter_aggregation_evaluator.rb +1 -1
- data/lib/elasticated/aggregations/group_aggregation.rb +14 -11
- data/lib/elasticated/aggregations/range_aggregation.rb +10 -11
- data/lib/elasticated/aggregations/range_aggregation_evaluator.rb +1 -1
- data/lib/elasticated/aggregations/ranges_builder.rb +2 -2
- data/lib/elasticated/aggregations/safe_date_histogram_aggregation.rb +7 -2
- data/lib/elasticated/aggregations/subaggregated.rb +1 -1
- data/lib/elasticated/boolean_clause.rb +4 -3
- data/lib/elasticated/bulk_actions/create_action.rb +14 -0
- data/lib/elasticated/bulk_actions/delete_action.rb +30 -0
- data/lib/elasticated/bulk_actions/index_action.rb +35 -0
- data/lib/elasticated/bulk_actions/standard_action.rb +22 -0
- data/lib/elasticated/bulk_actions/update_action.rb +44 -0
- data/lib/elasticated/bulk_actions/upsert_action.rb +14 -0
- data/lib/elasticated/bulk_request.rb +58 -0
- data/lib/elasticated/bulk_request/response.rb +32 -0
- data/lib/elasticated/bulk_request/response_item.rb +39 -0
- data/lib/elasticated/client.rb +27 -3
- data/lib/elasticated/conditions/custom_condition.rb +3 -3
- data/lib/elasticated/conditions/range_condition.rb +5 -2
- data/lib/elasticated/conditions/script_condition.rb +3 -3
- data/lib/elasticated/conditions/standard_condition.rb +4 -5
- data/lib/elasticated/conditions/term_condition.rb +22 -0
- data/lib/elasticated/conditions/terms_condition.rb +2 -2
- data/lib/elasticated/conditions_builder.rb +19 -4
- data/lib/elasticated/delimiters/date_field_delimiter.rb +21 -12
- data/lib/elasticated/delimiters/standard_field_delimiter.rb +18 -2
- data/lib/elasticated/delimiters/term_field_delimiter.rb +6 -5
- data/lib/elasticated/document.rb +20 -1
- data/lib/elasticated/enum.rb +17 -0
- data/lib/elasticated/index_selector.rb +26 -25
- data/lib/elasticated/mapping.rb +2 -4
- data/lib/elasticated/mapping/builder.rb +3 -2
- data/lib/elasticated/mapping/fields_builder.rb +13 -9
- data/lib/elasticated/mapping/object_builder.rb +38 -4
- data/lib/elasticated/mapping/type_builder.rb +3 -5
- data/lib/elasticated/mixins/block_evaluation.rb +17 -0
- data/lib/elasticated/mixins/clonable.rb +60 -0
- data/lib/elasticated/mixins/configurable.rb +22 -0
- data/lib/elasticated/mixins/inspectionable.rb +16 -0
- data/lib/elasticated/partitioned_repository.rb +24 -18
- data/lib/elasticated/query.rb +27 -21
- data/lib/elasticated/query_aggregations.rb +5 -7
- data/lib/elasticated/query_conditions.rb +6 -3
- data/lib/elasticated/quick.rb +7 -0
- data/lib/elasticated/repository.rb +184 -40
- data/lib/elasticated/repository/intelligent_search.rb +3 -3
- data/lib/elasticated/repository/normal_search.rb +2 -2
- data/lib/elasticated/repository/resumable_search.rb +5 -5
- data/lib/elasticated/repository/scan_scroll_search.rb +4 -4
- data/lib/elasticated/repository/scroll_search.rb +3 -3
- data/lib/elasticated/repository/search.rb +7 -0
- data/lib/elasticated/repository/single_page_search.rb +1 -1
- data/lib/elasticated/results.rb +14 -0
- data/lib/version.rb +18 -25
- data/spec/aggregation_spec.rb +95 -16
- data/spec/bulk_request_spec.rb +158 -0
- data/spec/date_field_delimiter_spec.rb +50 -6
- data/spec/document_spec.rb +1 -5
- data/spec/integration_spec.rb +7 -7
- data/spec/mapping_spec.rb +128 -8
- data/spec/partitioned_repository_spec.rb +218 -0
- data/spec/query_conditions_spec.rb +98 -45
- data/spec/query_spec.rb +21 -28
- data/spec/repository_spec.rb +245 -0
- data/spec/results_spec.rb +0 -4
- data/spec/sample_responses/elasticsearch_bulk_response_1.json +35 -0
- data/spec/sample_responses/elasticsearch_bulk_response_2.json +20 -0
- data/spec/sample_responses/elasticsearch_count_1.json +8 -0
- data/spec/sample_responses/elasticsearch_count_2.json +8 -0
- data/spec/sample_responses/elasticsearch_get_response_1.json +10 -0
- data/spec/sample_responses/elasticsearch_get_response_2.json +6 -0
- data/spec/{elasticsearch_hit_1.json → sample_responses/elasticsearch_hit_1.json} +0 -0
- data/spec/sample_responses/elasticsearch_mget_response_1.json +25 -0
- data/spec/{elasticsearch_response_1.json → sample_responses/elasticsearch_response_1.json} +0 -0
- data/spec/{elasticsearch_response_2.json → sample_responses/elasticsearch_response_2.json} +0 -0
- data/spec/{elasticsearch_top_hits_response.json → sample_responses/elasticsearch_top_hits_response.json} +0 -0
- data/spec/spec_helper.rb +47 -0
- data/spec/spec_helper/fake_index_selector.rb +27 -0
- data/spec/term_field_delimiter_spec.rb +8 -8
- metadata +80 -26
- data/lib/elasticated/block_evaluation.rb +0 -15
- data/lib/elasticated/clonable.rb +0 -58
- data/lib/elasticated/configurable.rb +0 -20
- data/lib/elasticated/date_delimiter_factory.rb +0 -123
- data/lib/elasticated/delimiter_visitor.rb +0 -53
- data/lib/elasticated/inspectionable.rb +0 -9
- data/lib/elasticated/strategy_params_for_query_service.rb +0 -14
- data/lib/elasticated/term_delimiter_factory.rb +0 -73
- data/spec/delimiter_factory_spec.rb +0 -399
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eefc3eab5d4fd7000cb959f921e9d1622769c7df
|
4
|
+
data.tar.gz: 4cb4baa5ad341834938c175bffdad61669b63695
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
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
|
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/
|
11
|
-
|
12
|
-
require_relative 'elasticated/
|
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
|
10
|
-
include
|
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
|
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
|
-
|
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
|
-
|
31
|
-
compact ? count : { 'count' => count }
|
29
|
+
if compact && _subaggregations.empty?
|
30
|
+
count
|
32
31
|
else
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
@@ -2,12 +2,13 @@ module Elasticated
|
|
2
2
|
class GroupAggregation < TermsAggregation
|
3
3
|
include Subaggregated
|
4
4
|
|
5
|
-
attr_accessor :compact, :
|
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.
|
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[
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
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
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
|
@@ -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
|