chewy 6.0.0 → 7.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CODEOWNERS +1 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +39 -0
  4. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  5. data/.github/PULL_REQUEST_TEMPLATE.md +16 -0
  6. data/.github/dependabot.yml +42 -0
  7. data/.github/workflows/ruby.yml +60 -0
  8. data/.rubocop.yml +16 -8
  9. data/.rubocop_todo.yml +110 -22
  10. data/CHANGELOG.md +396 -105
  11. data/CODE_OF_CONDUCT.md +14 -0
  12. data/CONTRIBUTING.md +63 -0
  13. data/Gemfile +4 -10
  14. data/Guardfile +3 -1
  15. data/README.md +497 -275
  16. data/chewy.gemspec +5 -20
  17. data/gemfiles/base.gemfile +12 -0
  18. data/gemfiles/rails.6.1.activerecord.gemfile +10 -15
  19. data/gemfiles/rails.7.0.activerecord.gemfile +14 -0
  20. data/gemfiles/rails.7.1.activerecord.gemfile +14 -0
  21. data/lib/chewy/config.rb +60 -52
  22. data/lib/chewy/elastic_client.rb +31 -0
  23. data/lib/chewy/errors.rb +7 -10
  24. data/lib/chewy/fields/base.rb +79 -13
  25. data/lib/chewy/fields/root.rb +4 -14
  26. data/lib/chewy/index/actions.rb +54 -37
  27. data/lib/chewy/{type → index}/adapter/active_record.rb +30 -6
  28. data/lib/chewy/{type → index}/adapter/base.rb +2 -3
  29. data/lib/chewy/{type → index}/adapter/object.rb +27 -31
  30. data/lib/chewy/{type → index}/adapter/orm.rb +17 -18
  31. data/lib/chewy/index/aliases.rb +14 -5
  32. data/lib/chewy/index/crutch.rb +40 -0
  33. data/lib/chewy/index/import/bulk_builder.rb +311 -0
  34. data/lib/chewy/{type → index}/import/bulk_request.rb +6 -7
  35. data/lib/chewy/{type → index}/import/journal_builder.rb +11 -12
  36. data/lib/chewy/{type → index}/import/routine.rb +18 -17
  37. data/lib/chewy/{type → index}/import.rb +76 -32
  38. data/lib/chewy/{type → index}/mapping.rb +29 -34
  39. data/lib/chewy/index/observe/active_record_methods.rb +87 -0
  40. data/lib/chewy/index/observe/callback.rb +34 -0
  41. data/lib/chewy/index/observe.rb +17 -0
  42. data/lib/chewy/index/specification.rb +1 -0
  43. data/lib/chewy/{type → index}/syncer.rb +59 -59
  44. data/lib/chewy/{type → index}/witchcraft.rb +11 -7
  45. data/lib/chewy/{type → index}/wrapper.rb +2 -2
  46. data/lib/chewy/index.rb +67 -94
  47. data/lib/chewy/journal.rb +25 -14
  48. data/lib/chewy/log_subscriber.rb +5 -1
  49. data/lib/chewy/minitest/helpers.rb +86 -13
  50. data/lib/chewy/minitest/search_index_receiver.rb +24 -26
  51. data/lib/chewy/railtie.rb +6 -20
  52. data/lib/chewy/rake_helper.rb +169 -113
  53. data/lib/chewy/rspec/build_query.rb +12 -0
  54. data/lib/chewy/rspec/helpers.rb +55 -0
  55. data/lib/chewy/rspec/update_index.rb +55 -44
  56. data/lib/chewy/rspec.rb +2 -0
  57. data/lib/chewy/runtime/version.rb +1 -1
  58. data/lib/chewy/runtime.rb +1 -1
  59. data/lib/chewy/search/loader.rb +19 -41
  60. data/lib/chewy/search/parameters/collapse.rb +16 -0
  61. data/lib/chewy/search/parameters/concerns/query_storage.rb +2 -2
  62. data/lib/chewy/search/parameters/ignore_unavailable.rb +27 -0
  63. data/lib/chewy/search/parameters/indices.rb +13 -58
  64. data/lib/chewy/search/parameters/knn.rb +16 -0
  65. data/lib/chewy/search/parameters/order.rb +6 -19
  66. data/lib/chewy/search/parameters/source.rb +5 -1
  67. data/lib/chewy/search/parameters/storage.rb +1 -1
  68. data/lib/chewy/search/parameters/track_total_hits.rb +16 -0
  69. data/lib/chewy/search/parameters.rb +6 -4
  70. data/lib/chewy/search/query_proxy.rb +9 -2
  71. data/lib/chewy/search/request.rb +169 -134
  72. data/lib/chewy/search/response.rb +5 -5
  73. data/lib/chewy/search/scoping.rb +7 -8
  74. data/lib/chewy/search/scrolling.rb +13 -13
  75. data/lib/chewy/search.rb +9 -19
  76. data/lib/chewy/stash.rb +19 -30
  77. data/lib/chewy/strategy/active_job.rb +1 -1
  78. data/lib/chewy/strategy/atomic_no_refresh.rb +18 -0
  79. data/lib/chewy/strategy/base.rb +10 -0
  80. data/lib/chewy/strategy/delayed_sidekiq/scheduler.rb +168 -0
  81. data/lib/chewy/strategy/delayed_sidekiq/worker.rb +76 -0
  82. data/lib/chewy/strategy/delayed_sidekiq.rb +30 -0
  83. data/lib/chewy/strategy/lazy_sidekiq.rb +64 -0
  84. data/lib/chewy/strategy/sidekiq.rb +2 -1
  85. data/lib/chewy/strategy.rb +6 -19
  86. data/lib/chewy/version.rb +1 -1
  87. data/lib/chewy.rb +39 -86
  88. data/lib/generators/chewy/install_generator.rb +1 -1
  89. data/lib/tasks/chewy.rake +36 -32
  90. data/migration_guide.md +46 -8
  91. data/spec/chewy/config_spec.rb +16 -41
  92. data/spec/chewy/elastic_client_spec.rb +26 -0
  93. data/spec/chewy/fields/base_spec.rb +432 -147
  94. data/spec/chewy/fields/root_spec.rb +20 -28
  95. data/spec/chewy/fields/time_fields_spec.rb +5 -5
  96. data/spec/chewy/index/actions_spec.rb +368 -59
  97. data/spec/chewy/{type → index}/adapter/active_record_spec.rb +156 -40
  98. data/spec/chewy/{type → index}/adapter/object_spec.rb +21 -6
  99. data/spec/chewy/index/aliases_spec.rb +3 -3
  100. data/spec/chewy/index/import/bulk_builder_spec.rb +494 -0
  101. data/spec/chewy/{type → index}/import/bulk_request_spec.rb +5 -12
  102. data/spec/chewy/{type → index}/import/journal_builder_spec.rb +9 -19
  103. data/spec/chewy/{type → index}/import/routine_spec.rb +19 -19
  104. data/spec/chewy/{type → index}/import_spec.rb +164 -98
  105. data/spec/chewy/index/mapping_spec.rb +135 -0
  106. data/spec/chewy/index/observe/active_record_methods_spec.rb +68 -0
  107. data/spec/chewy/index/observe/callback_spec.rb +139 -0
  108. data/spec/chewy/index/observe_spec.rb +143 -0
  109. data/spec/chewy/index/settings_spec.rb +3 -1
  110. data/spec/chewy/index/specification_spec.rb +20 -30
  111. data/spec/chewy/{type → index}/syncer_spec.rb +14 -19
  112. data/spec/chewy/{type → index}/witchcraft_spec.rb +20 -22
  113. data/spec/chewy/index/wrapper_spec.rb +100 -0
  114. data/spec/chewy/index_spec.rb +60 -105
  115. data/spec/chewy/journal_spec.rb +25 -74
  116. data/spec/chewy/minitest/helpers_spec.rb +123 -15
  117. data/spec/chewy/minitest/search_index_receiver_spec.rb +28 -30
  118. data/spec/chewy/multi_search_spec.rb +4 -5
  119. data/spec/chewy/rake_helper_spec.rb +315 -55
  120. data/spec/chewy/rspec/build_query_spec.rb +34 -0
  121. data/spec/chewy/rspec/helpers_spec.rb +61 -0
  122. data/spec/chewy/rspec/update_index_spec.rb +74 -71
  123. data/spec/chewy/runtime_spec.rb +2 -2
  124. data/spec/chewy/search/loader_spec.rb +19 -53
  125. data/spec/chewy/search/pagination/kaminari_examples.rb +4 -6
  126. data/spec/chewy/search/pagination/kaminari_spec.rb +2 -2
  127. data/spec/chewy/search/parameters/collapse_spec.rb +5 -0
  128. data/spec/chewy/search/parameters/ignore_unavailable_spec.rb +67 -0
  129. data/spec/chewy/search/parameters/indices_spec.rb +26 -117
  130. data/spec/chewy/search/parameters/knn_spec.rb +5 -0
  131. data/spec/chewy/search/parameters/order_spec.rb +18 -11
  132. data/spec/chewy/search/parameters/query_storage_examples.rb +67 -21
  133. data/spec/chewy/search/parameters/search_after_spec.rb +4 -1
  134. data/spec/chewy/search/parameters/source_spec.rb +8 -2
  135. data/spec/chewy/search/parameters/track_total_hits_spec.rb +5 -0
  136. data/spec/chewy/search/parameters_spec.rb +18 -4
  137. data/spec/chewy/search/query_proxy_spec.rb +68 -17
  138. data/spec/chewy/search/request_spec.rb +292 -110
  139. data/spec/chewy/search/response_spec.rb +12 -12
  140. data/spec/chewy/search/scrolling_spec.rb +10 -17
  141. data/spec/chewy/search_spec.rb +40 -34
  142. data/spec/chewy/stash_spec.rb +9 -21
  143. data/spec/chewy/strategy/active_job_spec.rb +16 -16
  144. data/spec/chewy/strategy/atomic_no_refresh_spec.rb +60 -0
  145. data/spec/chewy/strategy/atomic_spec.rb +9 -10
  146. data/spec/chewy/strategy/delayed_sidekiq_spec.rb +208 -0
  147. data/spec/chewy/strategy/lazy_sidekiq_spec.rb +214 -0
  148. data/spec/chewy/strategy/sidekiq_spec.rb +12 -12
  149. data/spec/chewy/strategy_spec.rb +19 -15
  150. data/spec/chewy_spec.rb +24 -107
  151. data/spec/spec_helper.rb +3 -22
  152. data/spec/support/active_record.rb +25 -7
  153. metadata +78 -339
  154. data/.circleci/config.yml +0 -240
  155. data/Appraisals +0 -81
  156. data/gemfiles/rails.5.2.activerecord.gemfile +0 -17
  157. data/gemfiles/rails.5.2.mongoid.6.4.gemfile +0 -17
  158. data/gemfiles/rails.6.0.activerecord.gemfile +0 -17
  159. data/gemfiles/sequel.4.45.gemfile +0 -11
  160. data/lib/chewy/backports/deep_dup.rb +0 -46
  161. data/lib/chewy/backports/duplicable.rb +0 -91
  162. data/lib/chewy/search/pagination/will_paginate.rb +0 -43
  163. data/lib/chewy/search/parameters/types.rb +0 -20
  164. data/lib/chewy/strategy/resque.rb +0 -27
  165. data/lib/chewy/strategy/shoryuken.rb +0 -40
  166. data/lib/chewy/type/actions.rb +0 -43
  167. data/lib/chewy/type/adapter/mongoid.rb +0 -67
  168. data/lib/chewy/type/adapter/sequel.rb +0 -93
  169. data/lib/chewy/type/crutch.rb +0 -32
  170. data/lib/chewy/type/import/bulk_builder.rb +0 -122
  171. data/lib/chewy/type/observe.rb +0 -82
  172. data/lib/chewy/type.rb +0 -120
  173. data/lib/sequel/plugins/chewy_observe.rb +0 -63
  174. data/spec/chewy/search/pagination/will_paginate_examples.rb +0 -63
  175. data/spec/chewy/search/pagination/will_paginate_spec.rb +0 -23
  176. data/spec/chewy/search/parameters/types_spec.rb +0 -5
  177. data/spec/chewy/strategy/resque_spec.rb +0 -46
  178. data/spec/chewy/strategy/shoryuken_spec.rb +0 -70
  179. data/spec/chewy/type/actions_spec.rb +0 -50
  180. data/spec/chewy/type/adapter/mongoid_spec.rb +0 -372
  181. data/spec/chewy/type/adapter/sequel_spec.rb +0 -472
  182. data/spec/chewy/type/import/bulk_builder_spec.rb +0 -194
  183. data/spec/chewy/type/mapping_spec.rb +0 -175
  184. data/spec/chewy/type/observe_spec.rb +0 -137
  185. data/spec/chewy/type/wrapper_spec.rb +0 -100
  186. data/spec/chewy/type_spec.rb +0 -55
  187. data/spec/support/mongoid.rb +0 -93
  188. data/spec/support/sequel.rb +0 -80
@@ -8,27 +8,27 @@ module Chewy
8
8
  # @see Chewy::Search
9
9
  # @example
10
10
  # scope = Chewy::Search::Request.new(PlacesIndex)
11
- # # => <Chewy::Search::Request {:index=>["places"], :type=>["city", "country"]}>
11
+ # # => <Chewy::Search::Request {:index=>["places"], :body=>{}}>
12
12
  # scope.limit(20)
13
- # # => <Chewy::Search::Request {:index=>["places"], :type=>["city", "country"], :body=>{:size=>20}}>
13
+ # # => <Chewy::Search::Request {:index=>["places"], :body=>{:size=>20}}>
14
14
  # scope.order(:name).offset(10)
15
- # # => <Chewy::Search::Request {:index=>["places"], :type=>["city", "country"], :body=>{:sort=>["name"], :from=>10}}>
15
+ # # => <Chewy::Search::Request {:index=>["places"], :body=>{:sort=>["name"], :from=>10}}>
16
16
  class Request
17
17
  include Enumerable
18
18
  include Scoping
19
19
  include Scrolling
20
20
  UNDEFINED = Class.new.freeze
21
- EVERFIELDS = %w[_index _type _id _parent].freeze
21
+ EVERFIELDS = %w[_index _type _id _parent _routing].freeze
22
22
  DELEGATED_METHODS = %i[
23
- query filter post_filter order reorder docvalue_fields
24
- track_scores request_cache explain version profile
23
+ query filter post_filter knn order reorder docvalue_fields
24
+ track_scores track_total_hits request_cache explain version profile
25
25
  search_type preference limit offset terminate_after
26
26
  timeout min_score source stored_fields search_after
27
- load script_fields suggest aggs aggregations none
27
+ load script_fields suggest aggs aggregations collapse none
28
28
  indices_boost rescore highlight total total_count
29
29
  total_entries indices types delete_all count exists?
30
30
  exist? find pluck scroll_batches scroll_hits
31
- scroll_results scroll_wrappers
31
+ scroll_results scroll_wrappers ignore_unavailable
32
32
  ].to_set.freeze
33
33
  DEFAULT_BATCH_SIZE = 1000
34
34
  DEFAULT_PLUCK_BATCH_SIZE = 10_000
@@ -41,42 +41,32 @@ module Chewy
41
41
  EXTRA_STORAGES = %i[aggs suggest].freeze
42
42
  # An array of storage names that are changing the returned hist collection in any way.
43
43
  WHERE_STORAGES = %i[
44
- query filter post_filter none types min_score rescore indices_boost
44
+ query filter post_filter knn none min_score rescore indices_boost collapse
45
45
  ].freeze
46
46
 
47
47
  delegate :hits, :wrappers, :objects, :records, :documents,
48
- :object_hash, :record_hash, :document_hash,
49
- :total, :max_score, :took, :timed_out?, to: :response
48
+ :object_hash, :record_hash, :document_hash,
49
+ :total, :max_score, :took, :timed_out?, to: :response
50
50
  delegate :each, :size, :to_a, :[], to: :wrappers
51
51
  alias_method :to_ary, :to_a
52
52
  alias_method :total_count, :total
53
53
  alias_method :total_entries, :total
54
54
 
55
- # The class is initialized with the list of chewy indexes and/or
56
- # types, which are later used to compose requests.
55
+ # The class is initialized with the list of chewy indexes,
56
+ # which are later used to compose requests.
57
57
  # Any symbol/string passed is treated as an index identifier.
58
58
  #
59
59
  # @example
60
60
  # Chewy::Search::Request.new(:places)
61
- # # => <Chewy::Search::Request {:index=>["places"]}>
61
+ # # => <Chewy::Search::Request {:index=>["places"], :body=>{}}>
62
62
  # Chewy::Search::Request.new(PlacesIndex)
63
- # # => <Chewy::Search::Request {:index=>["places"], :type=>["city", "country"]}>
64
- # Chewy::Search::Request.new(PlacesIndex::City)
65
- # # => <Chewy::Search::Request {:index=>["places"], :type=>["city"]}>
66
- # Chewy::Search::Request.new(UsersIndex, PlacesIndex::City)
67
- # # => <Chewy::Search::Request {:index=>["users", "places"], :type=>["city", "user"]}>
68
- # @param indexes_or_types [Array<Chewy::Index, Chewy::Type, String, Symbol>] indices and types in any combinations
69
- def initialize(*indices_or_types)
70
- indices = indices_or_types.reject do |klass|
71
- klass.is_a?(Class) && klass < Chewy::Type
72
- end
73
-
74
- types = indices_or_types.select do |klass|
75
- klass.is_a?(Class) && klass < Chewy::Type
76
- end
77
-
63
+ # # => <Chewy::Search::Request {:index=>["places"], :body=>{}}>
64
+ # Chewy::Search::Request.new(UsersIndex, PlacesIndex)
65
+ # # => <Chewy::Search::Request {:index=>["users", "places"], :body=>{}}>
66
+ # @param indexes [Array<Chewy::Index, String, Symbol>] indexes
67
+ def initialize(*indexes)
78
68
  parameters.modify!(:indices) do
79
- replace!(indices: indices, types: types)
69
+ replace!(indices: indexes)
80
70
  end
81
71
  end
82
72
 
@@ -138,17 +128,17 @@ module Chewy
138
128
  "<#{self.class} #{render}>"
139
129
  end
140
130
 
141
- # @!group Chainable request modificators
131
+ # @!group Chainable request modifications
142
132
 
143
133
  # @!method query(query_hash=nil, &block)
144
- # Adds `quer` parameter to the search request body.
134
+ # Adds `query` parameter to the search request body.
145
135
  #
146
136
  # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-query.html
147
137
  # @see Chewy::Search::Parameters::Query
148
138
  # @return [Chewy::Search::Request, Chewy::Search::QueryProxy]
149
139
  #
150
140
  # @overload query(query_hash)
151
- # If pure hash is passed it goes straight to the `quer` parameter storage.
141
+ # If pure hash is passed it goes straight to the `query` parameter storage.
152
142
  # Acts exactly the same way as {Chewy::Search::QueryProxy#must}.
153
143
  #
154
144
  # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html
@@ -167,7 +157,7 @@ module Chewy
167
157
  # @example
168
158
  # PlacesIndex.query { match name: 'Moscow' }
169
159
  # # => <PlacesIndex::Query {..., :body=>{:query=>{:match=>{:name=>"Moscow"}}}}>
170
- # @yield the block is processed by `elasticsearch-ds` gem
160
+ # @yield the block is processed by `elasticsearch-dsl` gem
171
161
  # @return [Chewy::Search::Request]
172
162
  #
173
163
  # @overload query
@@ -183,7 +173,7 @@ module Chewy
183
173
  # @return [Chewy::Search::QueryProxy]
184
174
  #
185
175
  # @!method filter(query_hash=nil, &block)
186
- # Adds `filte` context of the `quer` parameter at the
176
+ # Adds `filter` context of the `query` parameter at the
187
177
  # search request body.
188
178
  #
189
179
  # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-filter-context.html
@@ -191,7 +181,7 @@ module Chewy
191
181
  # @return [Chewy::Search::Request, Chewy::Search::QueryProxy]
192
182
  #
193
183
  # @overload filter(query_hash)
194
- # If pure hash is passed it goes straight to the `filte` context of the `quer` parameter storage.
184
+ # If pure hash is passed it goes straight to the `filter` context of the `query` parameter storage.
195
185
  # Acts exactly the same way as {Chewy::Search::QueryProxy#must}.
196
186
  #
197
187
  # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html
@@ -212,7 +202,7 @@ module Chewy
212
202
  # PlacesIndex.filter { match name: 'Moscow' }
213
203
  # # => <PlacesIndex::Query {..., :body=>{:query=>{:bool=>{
214
204
  # # :filter=>{:match=>{:name=>"Moscow"}}}}}}>
215
- # @yield the block is processed by `elasticsearch-ds` gem
205
+ # @yield the block is processed by `elasticsearch-dsl` gem
216
206
  # @return [Chewy::Search::Request]
217
207
  #
218
208
  # @overload filter
@@ -230,7 +220,7 @@ module Chewy
230
220
  # @!method post_filter(query_hash=nil, &block)
231
221
  # Adds `post_filter` parameter to the search request body.
232
222
  #
233
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-post-filter.html
223
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/filter-search-results.html#post-filter
234
224
  # @see Chewy::Search::Parameters::PostFilter
235
225
  # @return [Chewy::Search::Request, Chewy::Search::QueryProxy]
236
226
  #
@@ -254,7 +244,7 @@ module Chewy
254
244
  # @example
255
245
  # PlacesIndex.post_filter { match name: 'Moscow' }
256
246
  # # => <PlacesIndex::Query {..., :body=>{:post_filter=>{:match=>{:name=>"Moscow"}}}}>
257
- # @yield the block is processed by `elasticsearch-ds` gem
247
+ # @yield the block is processed by `elasticsearch-dsl` gem
258
248
  # @return [Chewy::Search::Request]
259
249
  #
260
250
  # @overload post_filter
@@ -285,7 +275,7 @@ module Chewy
285
275
  # PlacesIndex.order(:name, population: {order: :asc}).order(:coordinates)
286
276
  # # => <PlacesIndex::Query {..., :body=>{:sort=>["name", {"population"=>{:order=>:asc}}, "coordinates"]}}>
287
277
  # @see Chewy::Search::Parameters::Order
288
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html
278
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/sort-search-results.html
289
279
  # @param values [Array<Hash, String, Symbol>] sort fields and options
290
280
  # @return [Chewy::Search::Request]
291
281
  #
@@ -296,7 +286,7 @@ module Chewy
296
286
  # PlacesIndex.docvalue_fields(:name).docvalue_fields(:population, :coordinates)
297
287
  # # => <PlacesIndex::Query {..., :body=>{:docvalue_fields=>["name", "population", "coordinates"]}}>
298
288
  # @see Chewy::Search::Parameters::DocvalueFields
299
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-docvalue-fields.html
289
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html#docvalue-fields
300
290
  # @param values [Array<String, Symbol>] field names
301
291
  # @return [Chewy::Search::Request]
302
292
  %i[order docvalue_fields].each do |name|
@@ -305,34 +295,18 @@ module Chewy
305
295
  end
306
296
  end
307
297
 
308
- # @!method indices(*values)
309
- # Modifies `index` request parameter. Updates the storage on every call.
310
- # Added passed indexes to the parameter list.
311
- #
312
- # @example
313
- # UsersIndex.indices(CitiesIndex).indices(:another)
314
- # # => <UsersIndex::Query {:index=>["another", "cities", "users"], :type=>["city", "user"]}>
315
- # @see Chewy::Search::Parameters::Indices
316
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html
317
- # @param values [Array<Chewy::Index, String, Symbol>] index names
318
- # @return [Chewy::Search::Request]
319
- #
320
- # @!method types(*values)
321
- # Modifies `type` request parameter. Updates the storage on every call.
322
- # Constrains types passed on the request initialization or adds them
323
- # to the list depending on circumstances.
298
+ # Modifies `index` request parameter. Updates the storage on every call.
299
+ # Added passed indexes to the parameter list.
324
300
  #
325
- # @example
326
- # UsersIndex.types(CitiesIndex::City).types(:unexistent)
327
- # # => <UsersIndex::Query {:index=>["cities", "users"], :type=>["city", "user"]}>
328
- # @see Chewy::Search::Parameters::Indices
329
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html
330
- # @param values [Array<Chewy::Type, String, Symbol>] type names
331
- # @return [Chewy::Search::Request]
332
- %i[indices types].each do |name|
333
- define_method name do |value, *values|
334
- modify(:indices) { update!(name => [value, *values]) }
335
- end
301
+ # @example
302
+ # UsersIndex.indices(CitiesIndex).indices(:another)
303
+ # # => <UsersIndex::Query {:index=>["another", "cities", "users"]}>
304
+ # @see Chewy::Search::Parameters::Indices
305
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html
306
+ # @param values [Array<Chewy::Index, String, Symbol>] index names
307
+ # @return [Chewy::Search::Request]
308
+ def indices(value, *values)
309
+ modify(:indices) { update!(indices: [value, *values]) }
336
310
  end
337
311
 
338
312
  # @overload reorder(*values)
@@ -342,7 +316,7 @@ module Chewy
342
316
  # PlacesIndex.order(:name, population: {order: :asc}).reorder(:coordinates)
343
317
  # # => <PlacesIndex::Query {..., :body=>{:sort=>["coordinates"]}}>
344
318
  # @see Chewy::Search::Parameters::Order
345
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html
319
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/sort-search-results.html
346
320
  # @param values [Array<Hash, String, Symbol>] sort fields and options
347
321
  # @return [Chewy::Search::Request]
348
322
  def reorder(value, *values)
@@ -356,9 +330,22 @@ module Chewy
356
330
  # PlacesIndex.track_scores
357
331
  # # => <PlacesIndex::Query {..., :body=>{:track_scores=>true}}>
358
332
  # PlacesIndex.track_scores.track_scores(false)
359
- # # => <PlacesIndex::Query {:index=>["places"], :type=>["city", "country"]}>
333
+ # # => <PlacesIndex::Query {:index=>["places"]}>
360
334
  # @see Chewy::Search::Parameters::TrackScores
361
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-request-sort.html#_track_scores
335
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/sort-search-results.html#_track_scores
336
+ # @param value [true, false]
337
+ # @return [Chewy::Search::Request]
338
+ #
339
+ # @!method track_total_hits(value = true)
340
+ # Replaces the value of the `track_total_hits` parameter with the provided value.
341
+ #
342
+ # @example
343
+ # PlacesIndex.track_total_hits
344
+ # # => <PlacesIndex::Query {..., :body=>{:track_total_hits=>true}}>
345
+ # PlacesIndex.track_total_hits.track_total_hits(false)
346
+ # # => <PlacesIndex::Query {:index=>["places"]}>
347
+ # @see Chewy::Search::Parameters::TrackTotalHits
348
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-your-data.html#track-total-hits
362
349
  # @param value [true, false]
363
350
  # @return [Chewy::Search::Request]
364
351
  #
@@ -369,9 +356,9 @@ module Chewy
369
356
  # PlacesIndex.explain
370
357
  # # => <PlacesIndex::Query {..., :body=>{:explain=>true}}>
371
358
  # PlacesIndex.explain.explain(false)
372
- # # => <PlacesIndex::Query {:index=>["places"], :type=>["city", "country"]}>
359
+ # # => <PlacesIndex::Query {:index=>["places"]}>
373
360
  # @see Chewy::Search::Parameters::Explain
374
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-request-explain.html
361
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-explain.html
375
362
  # @param value [true, false]
376
363
  # @return [Chewy::Search::Request]
377
364
  #
@@ -382,9 +369,9 @@ module Chewy
382
369
  # PlacesIndex.version
383
370
  # # => <PlacesIndex::Query {..., :body=>{:version=>true}}>
384
371
  # PlacesIndex.version.version(false)
385
- # # => <PlacesIndex::Query {:index=>["places"], :type=>["city", "country"]}>
372
+ # # => <PlacesIndex::Query {:index=>["places"]}>
386
373
  # @see Chewy::Search::Parameters::Version
387
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-request-version.html
374
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html
388
375
  # @param value [true, false]
389
376
  # @return [Chewy::Search::Request]
390
377
  #
@@ -395,9 +382,9 @@ module Chewy
395
382
  # PlacesIndex.profile
396
383
  # # => <PlacesIndex::Query {..., :body=>{:profile=>true}}>
397
384
  # PlacesIndex.profile.profile(false)
398
- # # => <PlacesIndex::Query {:index=>["places"], :type=>["city", "country"]}>
385
+ # # => <PlacesIndex::Query {:index=>["places"]}>
399
386
  # @see Chewy::Search::Parameters::Profile
400
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-profile.html
387
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-profile.html
401
388
  # @param value [true, false]
402
389
  # @return [Chewy::Search::Request]
403
390
  #
@@ -414,7 +401,7 @@ module Chewy
414
401
  # @see https://en.wikipedia.org/wiki/Null_Object_pattern
415
402
  # @param value [true, false]
416
403
  # @return [Chewy::Search::Request]
417
- %i[track_scores explain version profile none].each do |name|
404
+ %i[track_scores track_total_hits explain version profile none].each do |name|
418
405
  define_method name do |value = true|
419
406
  modify(name) { replace!(value) }
420
407
  end
@@ -431,7 +418,7 @@ module Chewy
431
418
  # PlacesIndex.request_cache(false)
432
419
  # # => <PlacesIndex::Query {..., :body=>{:request_cache=>false}}>
433
420
  # @see Chewy::Search::Parameters::RequestCache
434
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/5.4/shard-request-cache.html#_enabling_and_disabling_caching_per_request
421
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/shard-request-cache.html#_enabling_and_disabling_caching_per_request
435
422
  # @param value [true, false, nil]
436
423
  # @return [Chewy::Search::Request]
437
424
  #
@@ -442,7 +429,7 @@ module Chewy
442
429
  # PlacesIndex.search_type(:dfs_query_then_fetch)
443
430
  # # => <PlacesIndex::Query {..., :body=>{:search_type=>"dfs_query_then_fetch"}}>
444
431
  # @see Chewy::Search::Parameters::SearchType
445
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-request-search-type.html
432
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html#search-type
446
433
  # @param value [String, Symbol]
447
434
  # @return [Chewy::Search::Request]
448
435
  #
@@ -453,7 +440,7 @@ module Chewy
453
440
  # PlacesIndex.preference(:_primary_first)
454
441
  # # => <PlacesIndex::Query {..., :body=>{:preference=>"_primary_first"}}>
455
442
  # @see Chewy::Search::Parameters::Preference
456
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-request-preference.html
443
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html#search-preference
457
444
  # @param value [String, Symbol]
458
445
  # @return [Chewy::Search::Request]
459
446
  #
@@ -464,7 +451,7 @@ module Chewy
464
451
  # PlacesIndex.timeout('1m')
465
452
  # <PlacesIndex::Query {..., :body=>{:timeout=>"1m"}}>
466
453
  # @see Chewy::Search::Parameters::Timeout
467
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/5.4/common-options.html#time-units
454
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#time-units
468
455
  # @param value [String, Symbol]
469
456
  # @return [Chewy::Search::Request]
470
457
  #
@@ -475,7 +462,7 @@ module Chewy
475
462
  # PlacesIndex.limit(10)
476
463
  # <PlacesIndex::Query {..., :body=>{:size=>10}}>
477
464
  # @see Chewy::Search::Parameters::Limit
478
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-request-from-size.html
465
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html
479
466
  # @param value [String, Integer]
480
467
  # @return [Chewy::Search::Request]
481
468
  #
@@ -486,7 +473,7 @@ module Chewy
486
473
  # PlacesIndex.offset(10)
487
474
  # <PlacesIndex::Query {..., :body=>{:from=>10}}>
488
475
  # @see Chewy::Search::Parameters::Offset
489
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-request-from-size.html
476
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html
490
477
  # @param value [String, Integer]
491
478
  # @return [Chewy::Search::Request]
492
479
  #
@@ -497,7 +484,7 @@ module Chewy
497
484
  # PlacesIndex.terminate_after(10)
498
485
  # <PlacesIndex::Query {..., :body=>{:terminate_after=>10}}>
499
486
  # @see Chewy::Search::Parameters::Offset
500
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-request-body.html
487
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-your-data.html#quickly-check-for-matching-docs
501
488
  # @param value [String, Integer]
502
489
  # @return [Chewy::Search::Request]
503
490
  #
@@ -508,10 +495,43 @@ module Chewy
508
495
  # PlacesIndex.min_score(2)
509
496
  # <PlacesIndex::Query {..., :body=>{:min_score=>2.0}}>
510
497
  # @see Chewy::Search::Parameters::Offset
511
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-request-min-score.html
498
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html#search-api-min-score
512
499
  # @param value [String, Integer, Float]
513
500
  # @return [Chewy::Search::Request]
514
- %i[request_cache search_type preference timeout limit offset terminate_after min_score].each do |name|
501
+ #
502
+ # @!method ignore_unavailable(value)
503
+ # Replaces the value of the `ignore_unavailable` request part.
504
+ #
505
+ # @example
506
+ # PlacesIndex.ignore_unavailable(true)
507
+ # <PlacesIndex::Query {..., :ignore_unavailable => true, :body=>{ ... }}>
508
+ # @see Chewy::Search::Parameters::IgnoreUnavailable
509
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-index.html#multi-index
510
+ # @param value [true, false, nil]
511
+ # @return [Chewy::Search::Request]
512
+ #
513
+ # @!method collapse(value)
514
+ # Replaces the value of the `collapse` request part.
515
+ #
516
+ # @example
517
+ # PlacesIndex.collapse(field: :name)
518
+ # # => <PlacesIndex::Query {..., :body=>{:collapse=>{"field"=>:name}}}>
519
+ # @see Chewy::Search::Parameters::Collapse
520
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/collapse-search-results.html
521
+ # @param value [Hash]
522
+ # @return [Chewy::Search::Request]
523
+ #
524
+ # @!method knn(value)
525
+ # Replaces the value of the `knn` request part.
526
+ #
527
+ # @example
528
+ # PlacesIndex.knn(field: :vector, query_vector: [4, 2], k: 5, num_candidates: 50)
529
+ # # => <PlacesIndex::Query {..., :body=>{:knn=>{"field"=>:vector, "query_vector"=>[4, 2], "k"=>5, "num_candidates"=>50}}}>
530
+ # @see Chewy::Search::Parameters::Knn
531
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/knn-search.html
532
+ # @param value [Hash]
533
+ # @return [Chewy::Search::Request]
534
+ %i[request_cache search_type preference timeout limit offset terminate_after min_score ignore_unavailable collapse knn].each do |name|
515
535
  define_method name do |value|
516
536
  modify(name) { replace!(value) }
517
537
  end
@@ -520,7 +540,7 @@ module Chewy
520
540
  # @!method source(*values)
521
541
  # Updates `_source` request part. Accepts either an array
522
542
  # of field names/templates or a hash with `includes` and `excludes`
523
- # keys. Source also can be disabled entierly or enabled again.
543
+ # keys. Source also can be disabled entirely or enabled again.
524
544
  #
525
545
  # @example
526
546
  # PlacesIndex.source(:name).source(includes: [:popularity], excludes: :description)
@@ -528,13 +548,13 @@ module Chewy
528
548
  # PlacesIndex.source(false)
529
549
  # # => <PlacesIndex::Query {..., :body=>{:_source=>false}}>
530
550
  # @see Chewy::Search::Parameters::Source
531
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-request-source-filtering.html
551
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html#source-filtering
532
552
  # @param values [true, false, {Symbol => Array<String, Symbol>, String, Symbol}, Array<String, Symbol>, String, Symbol]
533
553
  # @return [Chewy::Search::Request]
534
554
  #
535
555
  # @!method stored_fields(*values)
536
556
  # Updates `stored_fields` request part. Accepts an array of field
537
- # names. Can be entierly disabled and enabled back.
557
+ # names. Can be entirely disabled and enabled back.
538
558
  #
539
559
  # @example
540
560
  # PlacesIndex.stored_fields(:name).stored_fields(:description)
@@ -542,7 +562,7 @@ module Chewy
542
562
  # PlacesIndex.stored_fields(false)
543
563
  # # => <PlacesIndex::Query {..., :body=>{:stored_fields=>"_none_"}}>
544
564
  # @see Chewy::Search::Parameters::StoredFields
545
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-request-stored-fields.html
565
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html#stored-fields
546
566
  # @param values [true, false, String, Symbol, Array<String, Symbol>]
547
567
  # @return [Chewy::Search::Request]
548
568
  %i[source stored_fields].each do |name|
@@ -558,7 +578,7 @@ module Chewy
558
578
  # PlacesIndex.search_after(42, 'Moscow').search_after('London')
559
579
  # # => <PlacesIndex::Query {..., :body=>{:search_after=>["London"]}}>
560
580
  # @see Chewy::Search::Parameters::SearchAfter
561
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-request-search-after.html
581
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#search-after
562
582
  # @param value [Array, Object]
563
583
  # @return [Chewy::Search::Request]
564
584
  def search_after(value, *values)
@@ -566,9 +586,9 @@ module Chewy
566
586
  end
567
587
 
568
588
  # Stores ORM/ODM objects loading options. Options
569
- # might be define per-type or be global, depends on the adapter
589
+ # might be define per-index or be global, depends on the adapter
570
590
  # loading implementation. Also, there are 2 loading options to select
571
- # or exclude types from loading: `only` and `except` respectively.
591
+ # or exclude indexes from loading: `only` and `except` respectively.
572
592
  # Options are updated on further method calls.
573
593
  #
574
594
  # @example
@@ -593,7 +613,7 @@ module Chewy
593
613
  # # "field1"=>{:script=>{:lang=>"painless", :inline=>"some script here"}},
594
614
  # # "field2"=>{:script=>{:lang=>"painless", :inline=>"some script here"}}}}}>
595
615
  # @see Chewy::Search::Parameters::ScriptFields
596
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-request-script-fields.html
616
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html#script-fields
597
617
  # @param value [Hash]
598
618
  # @return [Chewy::Search::Request]
599
619
  #
@@ -605,7 +625,7 @@ module Chewy
605
625
  # PlacesIndex.indices_boost(index1: 1.2, index2: 1.3).indices_boost(index1: 1.5)
606
626
  # # => <PlacesIndex::Query {..., :body=>{:indices_boost=>[{"index2"=>1.3}, {"index1"=>1.5}]}}>
607
627
  # @see Chewy::Search::Parameters::IndicesBoost
608
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-request-index-boost.html
628
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multiple-indices.html#index-boost
609
629
  # @param value [{String, Symbol => String, Integer, Float}]
610
630
  # @return [Chewy::Search::Request]
611
631
  #
@@ -617,7 +637,7 @@ module Chewy
617
637
  # PlacesIndex.rescore(window_size: 100, query: {}).rescore(window_size: 200, query: {})
618
638
  # # => <PlacesIndex::Query {..., :body=>{:rescore=>[{:window_size=>100, :query=>{}}, {:window_size=>200, :query=>{}}]}}>
619
639
  # @see Chewy::Search::Parameters::Rescore
620
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-request-rescore.html
640
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/filter-search-results.html#rescore
621
641
  # @param value [Hash, Array<Hash>]
622
642
  # @return [Chewy::Search::Request]
623
643
  #
@@ -633,7 +653,7 @@ module Chewy
633
653
  # # "fields"=>{:description=>{:type=>"plain"}},
634
654
  # # "pre_tags"=>["<em>"], "post_tags"=>["</em>"]}}}>
635
655
  # @see Chewy::Search::Parameters::Highlight
636
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-request-highlighting.html
656
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/highlighting.html
637
657
  # @param value [Hash]
638
658
  # @return [Chewy::Search::Request]
639
659
  %i[script_fields indices_boost rescore highlight].each do |name|
@@ -656,7 +676,7 @@ module Chewy
656
676
  # # "names"=>{:text=>"tring out Elasticsearch"},
657
677
  # # "descriptions"=>{:text=>"some other text"}}}}>
658
678
  # @see Chewy::Search::Parameters::Suggest
659
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-suggesters.html
679
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html
660
680
  # @param value [Hash]
661
681
  # @return [Chewy::Search::Request]
662
682
  #
@@ -742,7 +762,10 @@ module Chewy
742
762
  # scope1.and(scope2)
743
763
  # # => <PlacesIndex::Query {..., :body=>{:query=>{:bool=>{
744
764
  # # :must=>[{:match=>{:name=>"London"}}, {:match=>{:name=>"Washington"}}],
745
- # # :filter=>{:bool=>{:must=>[{:term=>{:name=>"Moscow"}}, {:bool=>{:must_not=>{:term=>{:name=>"Berlin"}}}}]}}}}}}>
765
+ # # :filter=>{
766
+ # # :bool=>{:must=>[{:term=>{:name=>"Moscow"}}, {:bool=>{:must_not=>{:term=>{:name=>"Berlin"}}}}]}
767
+ # # }
768
+ # # }}}}>
746
769
  # @param other [Chewy::Search::Request] scope to merge
747
770
  # @return [Chewy::Search::Request] new scope
748
771
  #
@@ -759,7 +782,10 @@ module Chewy
759
782
  # scope1.or(scope2)
760
783
  # # => <PlacesIndex::Query {..., :body=>{:query=>{:bool=>{
761
784
  # # :should=>[{:match=>{:name=>"London"}}, {:match=>{:name=>"Washington"}}],
762
- # # :filter=>{:bool=>{:should=>[{:term=>{:name=>"Moscow"}}, {:bool=>{:must_not=>{:term=>{:name=>"Berlin"}}}}]}}}}}}>
785
+ # # :filter=>{
786
+ # # :bool=>{:should=>[{:term=>{:name=>"Moscow"}}, {:bool=>{:must_not=>{:term=>{:name=>"Berlin"}}}}]}
787
+ # # }
788
+ # # }}}}>
763
789
  # @param other [Chewy::Search::Request] scope to merge
764
790
  # @return [Chewy::Search::Request] new scope
765
791
  #
@@ -776,7 +802,13 @@ module Chewy
776
802
  # scope1.not(scope2)
777
803
  # # => <PlacesIndex::Query {..., :body=>{:query=>{:bool=>{
778
804
  # # :must=>{:match=>{:name=>"London"}}, :must_not=>{:match=>{:name=>"Washington"}},
779
- # # :filter=>{:bool=>{:must=>{:term=>{:name=>"Moscow"}}, :must_not=>{:bool=>{:must_not=>{:term=>{:name=>"Berlin"}}}}}}}}}}>
805
+ # # :filter=>{
806
+ # # :bool=>{
807
+ # # :must=>{:term=>{:name=>"Moscow"}},
808
+ # # :must_not=>{:bool=>{:must_not=>{:term=>{:name=>"Berlin"}}}}
809
+ # # }
810
+ # # }
811
+ # # }}}}>
780
812
  # @param other [Chewy::Search::Request] scope to merge
781
813
  # @return [Chewy::Search::Request] new scope
782
814
  %i[and or not].each do |name|
@@ -790,8 +822,8 @@ module Chewy
790
822
  # Returns a new scope containing only specified storages.
791
823
  #
792
824
  # @example
793
- # PlacesIndex.limit(10).offset(10).order(:name).except(:offset, :order)
794
- # # => <PlacesIndex::Query {..., :body=>{:size=>10}}>
825
+ # PlacesIndex.limit(10).offset(10).order(:name).only(:offset, :order)
826
+ # # => <PlacesIndex::Query {..., :body=>{:from=>10, :sort=>["name"]}}>
795
827
  # @param values [Array<String, Symbol>]
796
828
  # @return [Chewy::Search::Request] new scope
797
829
  def only(*values)
@@ -801,8 +833,8 @@ module Chewy
801
833
  # Returns a new scope containing all the storages except specified.
802
834
  #
803
835
  # @example
804
- # PlacesIndex.limit(10).offset(10).order(:name).only(:offset, :order)
805
- # # => <PlacesIndex::Query {..., :body=>{:from=>10, :sort=>["name"]}}>
836
+ # PlacesIndex.limit(10).offset(10).order(:name).except(:offset, :order)
837
+ # # => <PlacesIndex::Query {..., :body=>{:size=>10}}>
806
838
  # @param values [Array<String, Symbol>]
807
839
  # @return [Chewy::Search::Request] new scope
808
840
  def except(*values)
@@ -848,14 +880,14 @@ module Chewy
848
880
  # @overload first
849
881
  # If nothing is passed - it returns a single object.
850
882
  #
851
- # @return [Chewy::Type] result document
883
+ # @return [Chewy::Index] result document
852
884
  #
853
885
  # @overload first(limit)
854
886
  # If limit is provided - it returns the limit amount or less
855
887
  # of wrapper objects.
856
888
  #
857
889
  # @param limit [Integer] amount of requested results
858
- # @return [Array<Chewy::Type>] result document collection
890
+ # @return [Array<Chewy::Index>] result document collection
859
891
  def first(limit = UNDEFINED)
860
892
  request_limit = limit == UNDEFINED ? 1 : limit
861
893
 
@@ -874,7 +906,7 @@ module Chewy
874
906
  # If single id is passed - it returns a single object.
875
907
  #
876
908
  # @param id [Integer, String] id of the desired document
877
- # @return [Chewy::Type] result document
909
+ # @return [Chewy::Index] result document
878
910
  #
879
911
  # @overload find(*ids)
880
912
  # If several field are passed - it returns an array of wrappers.
@@ -882,7 +914,7 @@ module Chewy
882
914
  # batch size - uses scroll API to retrieve everything.
883
915
  #
884
916
  # @param ids [Array<Integer, String>] ids of the desired documents
885
- # @return [Array<Chewy::Type>] result documents
917
+ # @return [Array<Chewy::Index>] result documents
886
918
  def find(*ids)
887
919
  return super if block_given?
888
920
 
@@ -904,7 +936,7 @@ module Chewy
904
936
 
905
937
  # Returns and array of values for specified fields.
906
938
  # Uses `source` to restrict the list of returned fields.
907
- # Fields `_id`, `_type` and `_index` are also supported.
939
+ # Fields `_id`, `_type`, `_routing` and `_index` are also supported.
908
940
  #
909
941
  # @overload pluck(field)
910
942
  # If single field is passed - it returns and array of values.
@@ -941,15 +973,26 @@ module Chewy
941
973
  #
942
974
  # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html
943
975
  # @note The result hash is different for different API used.
944
- # @param refresh [true, false] field names
976
+ # @param refresh [true, false] Refreshes all shards involved in the delete by query
977
+ # @param wait_for_completion [true, false] wait for request completion or run it asynchronously
978
+ # and return task reference at `.tasks/task/${taskId}`.
979
+ # @param requests_per_second [Float] The throttle for this request in sub-requests per second
980
+ # @param scroll_size [Integer] Size of the scroll request that powers the operation
981
+
945
982
  # @return [Hash] the result of query execution
946
- def delete_all(refresh: true)
947
- request_body = only(WHERE_STORAGES).render.merge(refresh: refresh)
948
- ActiveSupport::Notifications.instrument 'delete_query.chewy',
949
- notification_payload(request: request_body) do
950
- request_body[:body] = {query: {match_all: {}}} if request_body[:body].empty?
951
- Chewy.client.delete_by_query(request_body)
952
- end
983
+ def delete_all(refresh: true, wait_for_completion: nil, requests_per_second: nil, scroll_size: nil)
984
+ request_body = only(WHERE_STORAGES).render.merge(
985
+ {
986
+ refresh: refresh,
987
+ wait_for_completion: wait_for_completion,
988
+ requests_per_second: requests_per_second,
989
+ scroll_size: scroll_size
990
+ }.compact
991
+ )
992
+ ActiveSupport::Notifications.instrument 'delete_query.chewy', notification_payload(request: request_body) do
993
+ request_body[:body] = {query: {match_all: {}}} if request_body[:body].empty?
994
+ Chewy.client.delete_by_query(request_body)
995
+ end
953
996
  end
954
997
 
955
998
  # Returns whether or not the query has been performed.
@@ -990,21 +1033,17 @@ module Chewy
990
1033
 
991
1034
  def perform(additional = {})
992
1035
  request_body = render.merge(additional)
993
- ActiveSupport::Notifications.instrument 'search_query.chewy',
994
- notification_payload(request: request_body) do
995
- begin
996
- Chewy.client.search(request_body)
997
- rescue Elasticsearch::Transport::Transport::Errors::NotFound
998
- {}
999
- end
1000
- end
1036
+ ActiveSupport::Notifications.instrument 'search_query.chewy', notification_payload(request: request_body) do
1037
+ Chewy.client.search(request_body)
1038
+ rescue Elasticsearch::Transport::Transport::Errors::NotFound
1039
+ {}
1040
+ end
1001
1041
  end
1002
1042
 
1003
1043
  def notification_payload(additional)
1004
1044
  {
1005
- indexes: _indices, types: _types,
1006
- index: _indices.one? ? _indices.first : _indices,
1007
- type: _types.one? ? _types.first : _types
1045
+ indexes: _indices,
1046
+ index: _indices.one? ? _indices.first : _indices
1008
1047
  }.merge(additional)
1009
1048
  end
1010
1049
 
@@ -1012,10 +1051,6 @@ module Chewy
1012
1051
  parameters[:indices].indices
1013
1052
  end
1014
1053
 
1015
- def _types
1016
- parameters[:indices].types
1017
- end
1018
-
1019
1054
  def raw_limit_value
1020
1055
  parameters[:limit].value
1021
1056
  end