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
@@ -1,387 +0,0 @@
1
- require_relative 'spec_helper'
2
- module Elasticated
3
-
4
- describe StrategyParamsForQueryService do
5
- let(:query){ Query.new }
6
- let(:service){StrategyParamsForQueryService.new}
7
-
8
- it 'should create empty delimiter' do
9
- delimiters = []
10
- expected = {}
11
- actual = service.strategy_params_for_query(delimiters, query)
12
- expect(actual).to eq expected
13
-
14
- delimiters = [Elasticated::Delimiters::TermFieldDelimiter.new(field: :account, as: :accounts)]
15
- actual = service.strategy_params_for_query(delimiters,query)
16
- expect(actual).to eq expected
17
-
18
- delimiters = [
19
- Elasticated::Delimiters::TermFieldDelimiter.new(field: :account, as: :accounts),
20
- Elasticated::Delimiters::DateFieldDelimiter.new(field: :date)
21
- ]
22
- actual = service.strategy_params_for_query(delimiters,query)
23
- expect(actual).to eq expected
24
- end
25
-
26
- it 'should create term dalimiter with a date' do
27
- delimiters = [Elasticated::Delimiters::TermFieldDelimiter.new(field: :date)]
28
- query.filter {equal :date, '2017-05-28'}
29
- expected = {date: ['2017-05-28']}
30
- actual = service.strategy_params_for_query(delimiters, query)
31
- expect(actual).to eq expected
32
- end
33
-
34
- it 'should create date delimiter with date since' do
35
- delimiters = [Elasticated::Delimiters::DateFieldDelimiter.new(field: :date)]
36
- query.filter {greater_than :date, '2017-05-28'}
37
- expected = {date_since: '2017-05-28'}
38
- actual = service.strategy_params_for_query(delimiters, query)
39
- expect(actual).to eq expected
40
- end
41
-
42
- it 'should create date delimiter with date until' do
43
- delimiters = [Elasticated::Delimiters::DateFieldDelimiter.new(field: :date)]
44
- query.filter {less_equal :date, '2017-05-30'}
45
- expected = {date_until: '2017-05-30'}
46
- actual = service.strategy_params_for_query(delimiters, query)
47
- expect(actual).to eq expected
48
- end
49
-
50
- it 'should create date delimiter with date since and date until' do
51
- delimiters = [Elasticated::Delimiters::DateFieldDelimiter.new(field: :date)]
52
- query.filter {between :date, '2017-05-28', '2017-05-30'}
53
- expected = {date_since: '2017-05-28', date_until: '2017-05-30'}
54
- actual = service.strategy_params_for_query(delimiters, query)
55
- expect(actual).to eq expected
56
- end
57
-
58
- it 'should create term delimiter from aggregations' do
59
- options = {delimit_by: [:aggregations]}
60
- delimiters = [Elasticated::Delimiters::TermFieldDelimiter.new(field: :account, as: :accounts)]
61
- query.aggregations do
62
- filter :account do
63
- conditions { equal :account, 39 }
64
- end
65
- filter :second_account do
66
- conditions { equal :account, 40 }
67
- end
68
- end
69
- expected = {accounts: [39, 40]}
70
- actual = service.strategy_params_for_query(delimiters, query, options)
71
- expect(actual).to eq expected
72
- end
73
-
74
- it 'should create date delimiter with date since from aggregations' do
75
- options = {delimit_by: [:aggregations]}
76
- delimiters = [Elasticated::Delimiters::DateFieldDelimiter.new(field: :date)]
77
- query.aggregations do
78
- filter :greater do
79
- conditions { greater_than :date, '2017-05-29' }
80
- end
81
- filter :greater_eq do
82
- conditions { greater_equal :date, '2017-05-27' }
83
- end
84
- end
85
- expected = {date_since: '2017-05-27'}
86
- actual = service.strategy_params_for_query(delimiters, query, options)
87
- expect(actual).to eq expected
88
- end
89
-
90
- it 'should create date delimiter with date until from aggregations' do
91
- options = {delimit_by: [:aggregations]}
92
- delimiters = [Elasticated::Delimiters::DateFieldDelimiter.new(field: :date)]
93
- query.aggregations do
94
- filter :less do
95
- conditions { less_than :date, '2017-05-29' }
96
- end
97
- filter :less_eq do
98
- conditions { less_equal :date, '2017-05-27' }
99
- end
100
- end
101
- expected = {date_until: '2017-05-29'}
102
- actual = service.strategy_params_for_query(delimiters, query, options)
103
- expect(actual).to eq expected
104
- end
105
-
106
- it 'should create date delimiter with date since and date until from aggregations' do
107
- options = {delimit_by: [:aggregations]}
108
- delimiters = [Elasticated::Delimiters::DateFieldDelimiter.new(field: :date)]
109
- query.aggregations do
110
- filter :greater_and_less_1 do
111
- conditions { between :date, '2017-05-24', '2017-05-25' }
112
- end
113
- filter :greater_and_less_2 do
114
- conditions { between :date, '2017-05-27', '2017-05-28' }
115
- end
116
- end
117
- expected = {date_since: '2017-05-24', date_until: '2017-05-28'}
118
- actual = service.strategy_params_for_query(delimiters, query, options)
119
- expect(actual).to eq expected
120
- end
121
-
122
- it 'should create date delimiter without date since nor date until from aggregations' do
123
- options = {delimit_by: [:aggregations]}
124
- delimiters = [Elasticated::Delimiters::DateFieldDelimiter.new(field: :date)]
125
- query.aggregations do
126
- filter :greater_and_less_1 do
127
- conditions { between :date, '2017-05-24', '2017-05-25' }
128
- end
129
- filter :greater_and_less_2 do
130
- conditions { between :date, '2017-05-27', '2017-05-28' }
131
- end
132
- filter :not_dates do
133
- conditions { equal :account, 39 }
134
- end
135
- end
136
- expected = {}
137
- actual = service.strategy_params_for_query(delimiters, query, options)
138
- expect(actual).to eq expected
139
- end
140
-
141
- it 'should create term delimiter with date from conditions and aggregations' do
142
- options = {delimit_by: [:conditions, :aggregations]}
143
- delimiters = [Elasticated::Delimiters::TermFieldDelimiter.new(field: :date)]
144
- query.filter {equal :date, '2017-05-23'}
145
- query.aggregations do
146
- filter :date_zero do
147
- conditions { equal :date, '2017-05-24' }
148
- end
149
- end
150
- expected = {date: ['2017-05-23']}
151
- actual = service.strategy_params_for_query(delimiters, query, options)
152
- expect(actual).to eq expected
153
- end
154
-
155
- it 'should create date delimiter with date since from conditions and aggregations' do
156
- options = {delimit_by: [:conditions, :aggregations]}
157
- delimiters = [Elasticated::Delimiters::DateFieldDelimiter.new(field: :date)]
158
- query.filter {greater_than :date, '2017-05-23'}
159
- query.aggregations do
160
- filter :greater_than_1 do
161
- conditions { greater_than :date, '2017-05-30' }
162
- end
163
- end
164
- expected = {date_since: '2017-05-23'}
165
- actual = service.strategy_params_for_query(delimiters, query, options)
166
- expect(actual).to eq expected
167
- end
168
-
169
- it 'should create date delimiter with date until from conditions and aggregations' do
170
- options = {delimit_by: [:conditions, :aggregations]}
171
- delimiters = [Elasticated::Delimiters::DateFieldDelimiter.new(field: :date)]
172
- query.filter {less_than :date, '2017-05-23'}
173
- query.aggregations do
174
- filter :greater_than_1 do
175
- conditions { less_equal :date, '2017-05-30' }
176
- end
177
- end
178
- expected = {date_until: '2017-05-23'}
179
- actual = service.strategy_params_for_query(delimiters, query, options)
180
- expect(actual).to eq expected
181
- end
182
-
183
- it 'should create date delimiter with date since and date until from conditions and aggregations' do
184
- options = {delimit_by: [:conditions, :aggregations]}
185
- delimiters = [Elasticated::Delimiters::DateFieldDelimiter.new(field: :date)]
186
- query.filter {between :date, '2017-05-23', '2017-05-30'}
187
- query.aggregations do
188
- filter :greater_and_less_1 do
189
- conditions { between :date, '2017-05-01', '2017-05-22' }
190
- end
191
- filter :greater_and_less_2 do
192
- conditions { between :date, '2017-05-31', '2017-06-01' }
193
- end
194
- end
195
- expected = {date_since: '2017-05-23', date_until: '2017-05-30'}
196
- actual = service.strategy_params_for_query(delimiters, query, options)
197
- expect(actual).to eq expected
198
- end
199
-
200
- it 'should create date delimiter with date since and date until from conditions and aggregations but without query conditions defined' do
201
- options = {delimit_by: [:conditions, :aggregations]}
202
- delimiters = [Elasticated::Delimiters::DateFieldDelimiter.new(field: :date)]
203
- query.aggregations do
204
- filter :greater_and_less_1 do
205
- conditions { between :date, '2017-05-01', '2017-05-22' }
206
- end
207
- filter :greater_and_less_2 do
208
- conditions { between :date, '2017-05-31', '2017-06-10' }
209
- end
210
- end
211
- expected = {date_since: '2017-05-01', date_until: '2017-06-10'}
212
- actual = service.strategy_params_for_query(delimiters, query, options)
213
- expect(actual).to eq expected
214
- end
215
-
216
- it 'should create date delimiter with date since from conditions and aggregations when one aggregation has not date until' do
217
- options = {delimit_by: [:conditions, :aggregations]}
218
- delimiters = [Elasticated::Delimiters::DateFieldDelimiter.new(field: :date)]
219
- query.filter {greater_than :date, '2017-05-23'}
220
- query.aggregations do
221
- filter :greater_and_less_1 do
222
- conditions { between :date, '2017-05-01', '2017-05-22' }
223
- end
224
- filter :greater_and_less_2 do
225
- conditions { between :date, '2017-05-31', '2017-06-10' }
226
- end
227
- filter :greater_eq do
228
- conditions { greater_equal :date, '2017-05-31' }
229
- end
230
- end
231
- expected = {date_since: '2017-05-23'}
232
- actual = service.strategy_params_for_query(delimiters, query, options)
233
- expect(actual).to eq expected
234
- end
235
-
236
- it 'should create date delimiter with date since from conditions and aggregations when one aggregation has account filter' do
237
- options = {delimit_by: [:conditions, :aggregations]}
238
- delimiters = [Elasticated::Delimiters::DateFieldDelimiter.new(field: :date)]
239
- query.filter {greater_than :date, '2017-05-23'}
240
- query.aggregations do
241
- filter :greater_and_less_1 do
242
- conditions { between :date, '2017-05-01', '2017-05-22' }
243
- end
244
- filter :greater_and_less_2 do
245
- conditions { between :date, '2017-05-31', '2017-06-10' }
246
- end
247
- filter :by_account do
248
- conditions { equal :account, 39 }
249
- end
250
- end
251
- expected = {date_since: '2017-05-23'}
252
- actual = service.strategy_params_for_query(delimiters, query, options)
253
- expect(actual).to eq expected
254
- end
255
-
256
- it 'should create date delimiter with date since from conditions and aggregations when one aggregation has account filter' do
257
- options = {delimit_by: [:conditions, :aggregations]}
258
- delimiters = [Elasticated::Delimiters::DateFieldDelimiter.new(field: :date), Elasticated::Delimiters::TermFieldDelimiter.new(field: :account, as: :accounts)]
259
- query.filter {greater_than :date, '2017-05-23'}
260
- query.aggregations do
261
- filter :greater_and_less_1 do
262
- conditions { between :date, '2017-05-01', '2017-05-22' }
263
- end
264
- filter :greater_and_less_2 do
265
- conditions { between :date, '2017-05-31', '2017-06-10' }
266
- end
267
- filter :by_account do
268
- conditions { equal :account, 39 }
269
- end
270
- end
271
- expected = {date_since: '2017-05-23'}
272
- actual = service.strategy_params_for_query(delimiters, query, options)
273
- expect(actual).to eq expected
274
- end
275
-
276
- it 'should create date delimiter as term' do
277
- options = {delimit_by: [:conditions]}
278
- delimiters = [Elasticated::Delimiters::DateFieldDelimiter.new(field: :date)]
279
- query.filter {equal :date, '2017-05-23'}
280
- expected = {date: '2017-05-23'}
281
- actual = service.strategy_params_for_query(delimiters, query, options)
282
- expect(actual).to eq expected
283
- end
284
-
285
- it 'should create date delimiter as term from aggregations' do
286
- options = {delimit_by: [:aggregations]}
287
- delimiters = [Elasticated::Delimiters::DateFieldDelimiter.new(field: :date)]
288
- query.aggregations do
289
- filter :greater_and_less_1 do
290
- conditions { equal :date, '2017-05-01' }
291
- end
292
- end
293
- expected = {date: '2017-05-01'}
294
- actual = service.strategy_params_for_query(delimiters, query, options)
295
- expect(actual).to eq expected
296
- end
297
-
298
- it 'should create date delimiter as term from condition and aggregations' do
299
- options = {delimit_by: [:conditions, :aggregations]}
300
- delimiters = [Elasticated::Delimiters::DateFieldDelimiter.new(field: :date)]
301
- query.filter {equal :date, '2017-05-23'}
302
- query.aggregations do
303
- filter :greater_and_less_1 do
304
- conditions { equal :date, '2017-05-01' }
305
- end
306
- end
307
- expected = {date: '2017-05-23'}
308
- actual = service.strategy_params_for_query(delimiters, query, options)
309
- expect(actual).to eq expected
310
- end
311
-
312
- it 'should create date delimiter as range from terms condition and aggregations' do
313
- options = {delimit_by: [:conditions, :aggregations]}
314
- delimiters = [Elasticated::Delimiters::DateFieldDelimiter.new(field: :date)]
315
- query.filter {equal :date, ['2017-05-23', '2017-06-01']}
316
- query.aggregations do
317
- filter :greater_and_less_1 do
318
- conditions { equal :date, '2017-05-01' }
319
- end
320
- end
321
- expected = {date_since: '2017-05-23', date_until: '2017-06-01'}
322
- actual = service.strategy_params_for_query(delimiters, query, options)
323
- expect(actual).to eq expected
324
- end
325
-
326
- it 'should not delimit by non-delimiters' do
327
- options = {delimit_by: [:conditions, :aggregations]}
328
- delimiters = [Elasticated::Delimiters::DateFieldDelimiter.new(field: :date)]
329
- query.filter {equal :date, ['2017-05-23', '2017-06-01']}
330
- query.aggregations do
331
- filter :nothing_to_do do
332
- conditions { equal :primary_keywords, ["hello"] }
333
- filter :another_filter do
334
- conditions { equal :secondary_keywords, ["bye"] }
335
- end
336
- end
337
- end
338
- expected = {date_since: '2017-05-23', date_until: '2017-06-01'}
339
- actual = service.strategy_params_for_query(delimiters, query, options)
340
- expect(actual).to eq expected
341
- end
342
-
343
- it 'should create date delimiter with different objects (test insights - part 1)' do
344
- options = {delimit_by: [:conditions, :aggregations]}
345
- delimiters = [Elasticated::Delimiters::DateFieldDelimiter.new(field: :date)]
346
- query.filter {equal :date, [Date.today]}
347
- query.aggregations do
348
- filter :terms_over_date do
349
- conditions { equal :date, '2017-01-05'}
350
- end
351
- end
352
- actual = service.strategy_params_for_query(delimiters, query, options)
353
- expected = {date: Date.today}
354
- expect(actual).to eq expected
355
- end
356
-
357
- it 'should create date delimiter with different objects (test insights - part 2)' do
358
- options = {delimit_by: [:conditions, :aggregations]}
359
- delimiters = [Elasticated::Delimiters::DateFieldDelimiter.new(field: :date)]
360
- query.filter {equal :date, '2017-01-05'}
361
- query.aggregations do
362
- filter :terms_over_date do
363
- conditions { equal :date, [Date.today]}
364
- end
365
- end
366
- actual = service.strategy_params_for_query(delimiters, query, options)
367
- expected = {date: '2017-01-05'}
368
- expect(actual).to eq expected
369
- end
370
-
371
- it 'should create date delimiter with different objects (test insights - part 3)' do
372
- options = {delimit_by: [:conditions, :aggregations]}
373
- delimiters = [Elasticated::Delimiters::DateFieldDelimiter.new(field: :date)]
374
- query.filter {equal :date, [Date.parse('2017-05-01')]}
375
- query.aggregations do
376
- filter :terms_over_date do
377
- conditions { equal :date, [Date.today]}
378
- end
379
- end
380
- actual = service.strategy_params_for_query(delimiters, query, options)
381
- expected = {date: Date.parse('2017-05-01')}
382
- expect(actual).to eq expected
383
- end
384
-
385
- end
386
-
387
- end