chewy 5.1.0 → 7.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (234) 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/workflows/ruby.yml +73 -0
  7. data/.rubocop.yml +13 -8
  8. data/.rubocop_todo.yml +110 -22
  9. data/CHANGELOG.md +449 -347
  10. data/CODE_OF_CONDUCT.md +14 -0
  11. data/CONTRIBUTING.md +63 -0
  12. data/Gemfile +3 -7
  13. data/Guardfile +3 -1
  14. data/LICENSE.txt +1 -1
  15. data/README.md +423 -311
  16. data/chewy.gemspec +8 -10
  17. data/gemfiles/rails.5.2.activerecord.gemfile +9 -14
  18. data/gemfiles/rails.6.0.activerecord.gemfile +11 -0
  19. data/gemfiles/rails.6.1.activerecord.gemfile +13 -0
  20. data/gemfiles/rails.7.0.activerecord.gemfile +13 -0
  21. data/lib/chewy/config.rb +42 -60
  22. data/lib/chewy/errors.rb +4 -10
  23. data/lib/chewy/fields/base.rb +80 -20
  24. data/lib/chewy/fields/root.rb +7 -17
  25. data/lib/chewy/index/actions.rb +62 -35
  26. data/lib/chewy/{type → index}/adapter/active_record.rb +18 -4
  27. data/lib/chewy/{type → index}/adapter/base.rb +2 -3
  28. data/lib/chewy/{type → index}/adapter/object.rb +28 -32
  29. data/lib/chewy/{type → index}/adapter/orm.rb +26 -24
  30. data/lib/chewy/index/aliases.rb +14 -5
  31. data/lib/chewy/{type → index}/crutch.rb +5 -5
  32. data/lib/chewy/index/import/bulk_builder.rb +311 -0
  33. data/lib/chewy/{type → index}/import/bulk_request.rb +6 -7
  34. data/lib/chewy/{type → index}/import/journal_builder.rb +11 -12
  35. data/lib/chewy/{type → index}/import/routine.rb +17 -16
  36. data/lib/chewy/{type → index}/import.rb +51 -33
  37. data/lib/chewy/{type → index}/mapping.rb +32 -37
  38. data/lib/chewy/index/observe/active_record_methods.rb +87 -0
  39. data/lib/chewy/index/observe/callback.rb +34 -0
  40. data/lib/chewy/index/observe.rb +17 -0
  41. data/lib/chewy/index/specification.rb +1 -0
  42. data/lib/chewy/{type → index}/syncer.rb +61 -62
  43. data/lib/chewy/{type → index}/witchcraft.rb +15 -9
  44. data/lib/chewy/{type → index}/wrapper.rb +13 -3
  45. data/lib/chewy/index.rb +46 -96
  46. data/lib/chewy/journal.rb +25 -14
  47. data/lib/chewy/minitest/helpers.rb +86 -13
  48. data/lib/chewy/minitest/search_index_receiver.rb +22 -26
  49. data/lib/chewy/multi_search.rb +62 -0
  50. data/lib/chewy/railtie.rb +6 -20
  51. data/lib/chewy/rake_helper.rb +136 -108
  52. data/lib/chewy/rspec/build_query.rb +12 -0
  53. data/lib/chewy/rspec/helpers.rb +55 -0
  54. data/lib/chewy/rspec/update_index.rb +55 -44
  55. data/lib/chewy/rspec.rb +2 -0
  56. data/lib/chewy/runtime.rb +1 -1
  57. data/lib/chewy/search/loader.rb +19 -41
  58. data/lib/chewy/search/parameters/collapse.rb +16 -0
  59. data/lib/chewy/search/parameters/concerns/query_storage.rb +2 -2
  60. data/lib/chewy/search/parameters/ignore_unavailable.rb +27 -0
  61. data/lib/chewy/search/parameters/indices.rb +12 -57
  62. data/lib/chewy/search/parameters/none.rb +1 -3
  63. data/lib/chewy/search/parameters/order.rb +6 -19
  64. data/lib/chewy/search/parameters/source.rb +5 -1
  65. data/lib/chewy/search/parameters/track_total_hits.rb +16 -0
  66. data/lib/chewy/search/parameters.rb +7 -4
  67. data/lib/chewy/search/query_proxy.rb +9 -2
  68. data/lib/chewy/search/request.rb +180 -154
  69. data/lib/chewy/search/response.rb +5 -5
  70. data/lib/chewy/search/scoping.rb +7 -8
  71. data/lib/chewy/search/scrolling.rb +16 -13
  72. data/lib/chewy/search.rb +7 -22
  73. data/lib/chewy/stash.rb +19 -30
  74. data/lib/chewy/strategy/active_job.rb +2 -2
  75. data/lib/chewy/strategy/atomic_no_refresh.rb +18 -0
  76. data/lib/chewy/strategy/base.rb +10 -0
  77. data/lib/chewy/strategy/lazy_sidekiq.rb +64 -0
  78. data/lib/chewy/strategy/sidekiq.rb +3 -2
  79. data/lib/chewy/strategy.rb +5 -19
  80. data/lib/chewy/version.rb +1 -1
  81. data/lib/chewy.rb +36 -80
  82. data/lib/generators/chewy/install_generator.rb +1 -1
  83. data/lib/tasks/chewy.rake +26 -32
  84. data/migration_guide.md +56 -0
  85. data/spec/chewy/config_spec.rb +15 -61
  86. data/spec/chewy/fields/base_spec.rb +432 -145
  87. data/spec/chewy/fields/root_spec.rb +20 -28
  88. data/spec/chewy/fields/time_fields_spec.rb +5 -5
  89. data/spec/chewy/index/actions_spec.rb +388 -55
  90. data/spec/chewy/{type → index}/adapter/active_record_spec.rb +110 -44
  91. data/spec/chewy/{type → index}/adapter/object_spec.rb +21 -6
  92. data/spec/chewy/index/aliases_spec.rb +3 -3
  93. data/spec/chewy/index/import/bulk_builder_spec.rb +494 -0
  94. data/spec/chewy/{type → index}/import/bulk_request_spec.rb +5 -12
  95. data/spec/chewy/{type → index}/import/journal_builder_spec.rb +14 -22
  96. data/spec/chewy/{type → index}/import/routine_spec.rb +19 -19
  97. data/spec/chewy/{type → index}/import_spec.rb +149 -96
  98. data/spec/chewy/index/mapping_spec.rb +135 -0
  99. data/spec/chewy/index/observe/active_record_methods_spec.rb +68 -0
  100. data/spec/chewy/index/observe/callback_spec.rb +139 -0
  101. data/spec/chewy/index/observe_spec.rb +143 -0
  102. data/spec/chewy/index/settings_spec.rb +3 -1
  103. data/spec/chewy/index/specification_spec.rb +20 -30
  104. data/spec/chewy/{type → index}/syncer_spec.rb +14 -19
  105. data/spec/chewy/{type → index}/witchcraft_spec.rb +34 -21
  106. data/spec/chewy/index/wrapper_spec.rb +100 -0
  107. data/spec/chewy/index_spec.rb +69 -137
  108. data/spec/chewy/journal_spec.rb +46 -91
  109. data/spec/chewy/minitest/helpers_spec.rb +122 -14
  110. data/spec/chewy/minitest/search_index_receiver_spec.rb +24 -26
  111. data/spec/chewy/multi_search_spec.rb +84 -0
  112. data/spec/chewy/rake_helper_spec.rb +293 -101
  113. data/spec/chewy/rspec/build_query_spec.rb +34 -0
  114. data/spec/chewy/rspec/helpers_spec.rb +61 -0
  115. data/spec/chewy/rspec/update_index_spec.rb +106 -102
  116. data/spec/chewy/runtime_spec.rb +2 -2
  117. data/spec/chewy/search/loader_spec.rb +19 -53
  118. data/spec/chewy/search/pagination/kaminari_examples.rb +3 -5
  119. data/spec/chewy/search/pagination/kaminari_spec.rb +1 -1
  120. data/spec/chewy/search/parameters/collapse_spec.rb +5 -0
  121. data/spec/chewy/search/parameters/ignore_unavailable_spec.rb +67 -0
  122. data/spec/chewy/search/parameters/indices_spec.rb +26 -118
  123. data/spec/chewy/search/parameters/none_spec.rb +1 -1
  124. data/spec/chewy/search/parameters/order_spec.rb +18 -11
  125. data/spec/chewy/search/parameters/query_storage_examples.rb +67 -21
  126. data/spec/chewy/search/parameters/search_after_spec.rb +4 -1
  127. data/spec/chewy/search/parameters/source_spec.rb +8 -2
  128. data/spec/chewy/search/parameters/track_total_hits_spec.rb +5 -0
  129. data/spec/chewy/search/parameters_spec.rb +23 -7
  130. data/spec/chewy/search/query_proxy_spec.rb +68 -17
  131. data/spec/chewy/search/request_spec.rb +344 -149
  132. data/spec/chewy/search/response_spec.rb +35 -25
  133. data/spec/chewy/search/scrolling_spec.rb +28 -26
  134. data/spec/chewy/search_spec.rb +69 -59
  135. data/spec/chewy/stash_spec.rb +16 -26
  136. data/spec/chewy/strategy/active_job_spec.rb +23 -10
  137. data/spec/chewy/strategy/atomic_no_refresh_spec.rb +60 -0
  138. data/spec/chewy/strategy/atomic_spec.rb +9 -10
  139. data/spec/chewy/strategy/lazy_sidekiq_spec.rb +214 -0
  140. data/spec/chewy/strategy/sidekiq_spec.rb +14 -10
  141. data/spec/chewy/strategy_spec.rb +19 -15
  142. data/spec/chewy_spec.rb +17 -110
  143. data/spec/spec_helper.rb +6 -29
  144. data/spec/support/active_record.rb +43 -5
  145. metadata +102 -198
  146. data/.travis.yml +0 -45
  147. data/Appraisals +0 -81
  148. data/LEGACY_DSL.md +0 -497
  149. data/gemfiles/rails.4.0.activerecord.gemfile +0 -15
  150. data/gemfiles/rails.4.1.activerecord.gemfile +0 -15
  151. data/gemfiles/rails.4.2.activerecord.gemfile +0 -16
  152. data/gemfiles/rails.4.2.mongoid.5.2.gemfile +0 -16
  153. data/gemfiles/rails.5.0.activerecord.gemfile +0 -16
  154. data/gemfiles/rails.5.0.mongoid.6.1.gemfile +0 -16
  155. data/gemfiles/rails.5.1.activerecord.gemfile +0 -16
  156. data/gemfiles/rails.5.1.mongoid.6.3.gemfile +0 -16
  157. data/gemfiles/sequel.4.45.gemfile +0 -11
  158. data/lib/chewy/backports/deep_dup.rb +0 -46
  159. data/lib/chewy/backports/duplicable.rb +0 -91
  160. data/lib/chewy/query/compose.rb +0 -68
  161. data/lib/chewy/query/criteria.rb +0 -191
  162. data/lib/chewy/query/filters.rb +0 -244
  163. data/lib/chewy/query/loading.rb +0 -110
  164. data/lib/chewy/query/nodes/and.rb +0 -25
  165. data/lib/chewy/query/nodes/base.rb +0 -17
  166. data/lib/chewy/query/nodes/bool.rb +0 -34
  167. data/lib/chewy/query/nodes/equal.rb +0 -34
  168. data/lib/chewy/query/nodes/exists.rb +0 -20
  169. data/lib/chewy/query/nodes/expr.rb +0 -28
  170. data/lib/chewy/query/nodes/field.rb +0 -110
  171. data/lib/chewy/query/nodes/has_child.rb +0 -15
  172. data/lib/chewy/query/nodes/has_parent.rb +0 -15
  173. data/lib/chewy/query/nodes/has_relation.rb +0 -59
  174. data/lib/chewy/query/nodes/match_all.rb +0 -11
  175. data/lib/chewy/query/nodes/missing.rb +0 -20
  176. data/lib/chewy/query/nodes/not.rb +0 -25
  177. data/lib/chewy/query/nodes/or.rb +0 -25
  178. data/lib/chewy/query/nodes/prefix.rb +0 -19
  179. data/lib/chewy/query/nodes/query.rb +0 -20
  180. data/lib/chewy/query/nodes/range.rb +0 -63
  181. data/lib/chewy/query/nodes/raw.rb +0 -15
  182. data/lib/chewy/query/nodes/regexp.rb +0 -35
  183. data/lib/chewy/query/nodes/script.rb +0 -20
  184. data/lib/chewy/query/pagination.rb +0 -25
  185. data/lib/chewy/query.rb +0 -1142
  186. data/lib/chewy/search/pagination/will_paginate.rb +0 -43
  187. data/lib/chewy/search/parameters/types.rb +0 -20
  188. data/lib/chewy/strategy/resque.rb +0 -27
  189. data/lib/chewy/strategy/shoryuken.rb +0 -40
  190. data/lib/chewy/type/actions.rb +0 -43
  191. data/lib/chewy/type/adapter/mongoid.rb +0 -67
  192. data/lib/chewy/type/adapter/sequel.rb +0 -93
  193. data/lib/chewy/type/import/bulk_builder.rb +0 -122
  194. data/lib/chewy/type/observe.rb +0 -82
  195. data/lib/chewy/type.rb +0 -117
  196. data/lib/sequel/plugins/chewy_observe.rb +0 -63
  197. data/spec/chewy/query/criteria_spec.rb +0 -700
  198. data/spec/chewy/query/filters_spec.rb +0 -201
  199. data/spec/chewy/query/loading_spec.rb +0 -124
  200. data/spec/chewy/query/nodes/and_spec.rb +0 -12
  201. data/spec/chewy/query/nodes/bool_spec.rb +0 -14
  202. data/spec/chewy/query/nodes/equal_spec.rb +0 -32
  203. data/spec/chewy/query/nodes/exists_spec.rb +0 -18
  204. data/spec/chewy/query/nodes/has_child_spec.rb +0 -59
  205. data/spec/chewy/query/nodes/has_parent_spec.rb +0 -59
  206. data/spec/chewy/query/nodes/match_all_spec.rb +0 -11
  207. data/spec/chewy/query/nodes/missing_spec.rb +0 -16
  208. data/spec/chewy/query/nodes/not_spec.rb +0 -14
  209. data/spec/chewy/query/nodes/or_spec.rb +0 -12
  210. data/spec/chewy/query/nodes/prefix_spec.rb +0 -16
  211. data/spec/chewy/query/nodes/query_spec.rb +0 -12
  212. data/spec/chewy/query/nodes/range_spec.rb +0 -32
  213. data/spec/chewy/query/nodes/raw_spec.rb +0 -11
  214. data/spec/chewy/query/nodes/regexp_spec.rb +0 -43
  215. data/spec/chewy/query/nodes/script_spec.rb +0 -15
  216. data/spec/chewy/query/pagination/kaminari_spec.rb +0 -5
  217. data/spec/chewy/query/pagination/will_paginate_spec.rb +0 -5
  218. data/spec/chewy/query/pagination_spec.rb +0 -39
  219. data/spec/chewy/query_spec.rb +0 -637
  220. data/spec/chewy/search/pagination/will_paginate_examples.rb +0 -63
  221. data/spec/chewy/search/pagination/will_paginate_spec.rb +0 -23
  222. data/spec/chewy/search/parameters/types_spec.rb +0 -5
  223. data/spec/chewy/strategy/resque_spec.rb +0 -46
  224. data/spec/chewy/strategy/shoryuken_spec.rb +0 -66
  225. data/spec/chewy/type/actions_spec.rb +0 -50
  226. data/spec/chewy/type/adapter/mongoid_spec.rb +0 -372
  227. data/spec/chewy/type/adapter/sequel_spec.rb +0 -472
  228. data/spec/chewy/type/import/bulk_builder_spec.rb +0 -279
  229. data/spec/chewy/type/mapping_spec.rb +0 -173
  230. data/spec/chewy/type/observe_spec.rb +0 -137
  231. data/spec/chewy/type/wrapper_spec.rb +0 -98
  232. data/spec/chewy/type_spec.rb +0 -55
  233. data/spec/support/mongoid.rb +0 -93
  234. data/spec/support/sequel.rb +0 -80
@@ -1,34 +1,34 @@
1
1
  module Chewy
2
2
  module Search
3
3
  # The main request DSL class. Supports multiple index requests.
4
- # Supports ES2 and ES5 search API and query DSL.
4
+ # Supports ES5 search API and query DSL.
5
5
  #
6
6
  # @note The class tries to be as immutable as possible,
7
7
  # so most of the methods return a new instance of the class.
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
23
  query filter post_filter order reorder docvalue_fields
24
- track_scores request_cache explain version profile
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 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
 
@@ -112,7 +102,16 @@ module Chewy
112
102
  # @see Chewy::Search::Response
113
103
  # @return [Chewy::Search::Response] a response object instance
114
104
  def response
115
- @response ||= Response.new(perform, loader, collection_paginator)
105
+ @response ||= build_response(perform)
106
+ end
107
+
108
+ # Wraps and sets the raw Elasticsearch response to provide access
109
+ # to convenience methods.
110
+ #
111
+ # @see Chewy::Search::Response
112
+ # @param from_elasticsearch [Hash] An Elasticsearch response
113
+ def response=(from_elasticsearch)
114
+ @response = build_response(from_elasticsearch)
116
115
  end
117
116
 
118
117
  # ES request body
@@ -129,17 +128,17 @@ module Chewy
129
128
  "<#{self.class} #{render}>"
130
129
  end
131
130
 
132
- # @!group Chainable request modificators
131
+ # @!group Chainable request modifications
133
132
 
134
133
  # @!method query(query_hash=nil, &block)
135
- # Adds `quer` parameter to the search request body.
134
+ # Adds `query` parameter to the search request body.
136
135
  #
137
136
  # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-query.html
138
137
  # @see Chewy::Search::Parameters::Query
139
138
  # @return [Chewy::Search::Request, Chewy::Search::QueryProxy]
140
139
  #
141
140
  # @overload query(query_hash)
142
- # 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.
143
142
  # Acts exactly the same way as {Chewy::Search::QueryProxy#must}.
144
143
  #
145
144
  # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html
@@ -158,7 +157,7 @@ module Chewy
158
157
  # @example
159
158
  # PlacesIndex.query { match name: 'Moscow' }
160
159
  # # => <PlacesIndex::Query {..., :body=>{:query=>{:match=>{:name=>"Moscow"}}}}>
161
- # @yield the block is processed by `elasticsearch-ds` gem
160
+ # @yield the block is processed by `elasticsearch-dsl` gem
162
161
  # @return [Chewy::Search::Request]
163
162
  #
164
163
  # @overload query
@@ -174,7 +173,7 @@ module Chewy
174
173
  # @return [Chewy::Search::QueryProxy]
175
174
  #
176
175
  # @!method filter(query_hash=nil, &block)
177
- # Adds `filte` context of the `quer` parameter at the
176
+ # Adds `filter` context of the `query` parameter at the
178
177
  # search request body.
179
178
  #
180
179
  # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-filter-context.html
@@ -182,7 +181,7 @@ module Chewy
182
181
  # @return [Chewy::Search::Request, Chewy::Search::QueryProxy]
183
182
  #
184
183
  # @overload filter(query_hash)
185
- # 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.
186
185
  # Acts exactly the same way as {Chewy::Search::QueryProxy#must}.
187
186
  #
188
187
  # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html
@@ -203,7 +202,7 @@ module Chewy
203
202
  # PlacesIndex.filter { match name: 'Moscow' }
204
203
  # # => <PlacesIndex::Query {..., :body=>{:query=>{:bool=>{
205
204
  # # :filter=>{:match=>{:name=>"Moscow"}}}}}}>
206
- # @yield the block is processed by `elasticsearch-ds` gem
205
+ # @yield the block is processed by `elasticsearch-dsl` gem
207
206
  # @return [Chewy::Search::Request]
208
207
  #
209
208
  # @overload filter
@@ -221,7 +220,7 @@ module Chewy
221
220
  # @!method post_filter(query_hash=nil, &block)
222
221
  # Adds `post_filter` parameter to the search request body.
223
222
  #
224
- # @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
225
224
  # @see Chewy::Search::Parameters::PostFilter
226
225
  # @return [Chewy::Search::Request, Chewy::Search::QueryProxy]
227
226
  #
@@ -245,7 +244,7 @@ module Chewy
245
244
  # @example
246
245
  # PlacesIndex.post_filter { match name: 'Moscow' }
247
246
  # # => <PlacesIndex::Query {..., :body=>{:post_filter=>{:match=>{:name=>"Moscow"}}}}>
248
- # @yield the block is processed by `elasticsearch-ds` gem
247
+ # @yield the block is processed by `elasticsearch-dsl` gem
249
248
  # @return [Chewy::Search::Request]
250
249
  #
251
250
  # @overload post_filter
@@ -276,7 +275,7 @@ module Chewy
276
275
  # PlacesIndex.order(:name, population: {order: :asc}).order(:coordinates)
277
276
  # # => <PlacesIndex::Query {..., :body=>{:sort=>["name", {"population"=>{:order=>:asc}}, "coordinates"]}}>
278
277
  # @see Chewy::Search::Parameters::Order
279
- # @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
280
279
  # @param values [Array<Hash, String, Symbol>] sort fields and options
281
280
  # @return [Chewy::Search::Request]
282
281
  #
@@ -287,7 +286,7 @@ module Chewy
287
286
  # PlacesIndex.docvalue_fields(:name).docvalue_fields(:population, :coordinates)
288
287
  # # => <PlacesIndex::Query {..., :body=>{:docvalue_fields=>["name", "population", "coordinates"]}}>
289
288
  # @see Chewy::Search::Parameters::DocvalueFields
290
- # @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
291
290
  # @param values [Array<String, Symbol>] field names
292
291
  # @return [Chewy::Search::Request]
293
292
  %i[order docvalue_fields].each do |name|
@@ -296,34 +295,18 @@ module Chewy
296
295
  end
297
296
  end
298
297
 
299
- # @!method indices(*values)
300
- # Modifies `index` request parameter. Updates the storage on every call.
301
- # Added passed indexes to the parameter list.
298
+ # Modifies `index` request parameter. Updates the storage on every call.
299
+ # Added passed indexes to the parameter list.
302
300
  #
303
- # @example
304
- # UsersIndex.indices(CitiesIndex).indices(:another)
305
- # # => <UsersIndex::Query {:index=>["another", "cities", "users"], :type=>["city", "user"]}>
306
- # @see Chewy::Search::Parameters::Indices
307
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html
308
- # @param values [Array<Chewy::Index, String, Symbol>] index names
309
- # @return [Chewy::Search::Request]
310
- #
311
- # @!method types(*values)
312
- # Modifies `type` request parameter. Updates the storage on every call.
313
- # Constrains types passed on the request initialization or adds them
314
- # to the list depending on circumstances.
315
- #
316
- # @example
317
- # UsersIndex.types(CitiesIndex::City).types(:unexistent)
318
- # # => <UsersIndex::Query {:index=>["cities", "users"], :type=>["city", "user"]}>
319
- # @see Chewy::Search::Parameters::Indices
320
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html
321
- # @param values [Array<Chewy::Type, String, Symbol>] type names
322
- # @return [Chewy::Search::Request]
323
- %i[indices types].each do |name|
324
- define_method name do |value, *values|
325
- modify(:indices) { update!(name => [value, *values]) }
326
- 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]) }
327
310
  end
328
311
 
329
312
  # @overload reorder(*values)
@@ -333,7 +316,7 @@ module Chewy
333
316
  # PlacesIndex.order(:name, population: {order: :asc}).reorder(:coordinates)
334
317
  # # => <PlacesIndex::Query {..., :body=>{:sort=>["coordinates"]}}>
335
318
  # @see Chewy::Search::Parameters::Order
336
- # @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
337
320
  # @param values [Array<Hash, String, Symbol>] sort fields and options
338
321
  # @return [Chewy::Search::Request]
339
322
  def reorder(value, *values)
@@ -347,9 +330,22 @@ module Chewy
347
330
  # PlacesIndex.track_scores
348
331
  # # => <PlacesIndex::Query {..., :body=>{:track_scores=>true}}>
349
332
  # PlacesIndex.track_scores.track_scores(false)
350
- # # => <PlacesIndex::Query {:index=>["places"], :type=>["city", "country"]}>
333
+ # # => <PlacesIndex::Query {:index=>["places"]}>
351
334
  # @see Chewy::Search::Parameters::TrackScores
352
- # @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
353
349
  # @param value [true, false]
354
350
  # @return [Chewy::Search::Request]
355
351
  #
@@ -360,9 +356,9 @@ module Chewy
360
356
  # PlacesIndex.explain
361
357
  # # => <PlacesIndex::Query {..., :body=>{:explain=>true}}>
362
358
  # PlacesIndex.explain.explain(false)
363
- # # => <PlacesIndex::Query {:index=>["places"], :type=>["city", "country"]}>
359
+ # # => <PlacesIndex::Query {:index=>["places"]}>
364
360
  # @see Chewy::Search::Parameters::Explain
365
- # @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
366
362
  # @param value [true, false]
367
363
  # @return [Chewy::Search::Request]
368
364
  #
@@ -373,9 +369,9 @@ module Chewy
373
369
  # PlacesIndex.version
374
370
  # # => <PlacesIndex::Query {..., :body=>{:version=>true}}>
375
371
  # PlacesIndex.version.version(false)
376
- # # => <PlacesIndex::Query {:index=>["places"], :type=>["city", "country"]}>
372
+ # # => <PlacesIndex::Query {:index=>["places"]}>
377
373
  # @see Chewy::Search::Parameters::Version
378
- # @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
379
375
  # @param value [true, false]
380
376
  # @return [Chewy::Search::Request]
381
377
  #
@@ -386,9 +382,9 @@ module Chewy
386
382
  # PlacesIndex.profile
387
383
  # # => <PlacesIndex::Query {..., :body=>{:profile=>true}}>
388
384
  # PlacesIndex.profile.profile(false)
389
- # # => <PlacesIndex::Query {:index=>["places"], :type=>["city", "country"]}>
385
+ # # => <PlacesIndex::Query {:index=>["places"]}>
390
386
  # @see Chewy::Search::Parameters::Profile
391
- # @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
392
388
  # @param value [true, false]
393
389
  # @return [Chewy::Search::Request]
394
390
  #
@@ -405,7 +401,7 @@ module Chewy
405
401
  # @see https://en.wikipedia.org/wiki/Null_Object_pattern
406
402
  # @param value [true, false]
407
403
  # @return [Chewy::Search::Request]
408
- %i[track_scores explain version profile none].each do |name|
404
+ %i[track_scores track_total_hits explain version profile none].each do |name|
409
405
  define_method name do |value = true|
410
406
  modify(name) { replace!(value) }
411
407
  end
@@ -422,7 +418,7 @@ module Chewy
422
418
  # PlacesIndex.request_cache(false)
423
419
  # # => <PlacesIndex::Query {..., :body=>{:request_cache=>false}}>
424
420
  # @see Chewy::Search::Parameters::RequestCache
425
- # @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
426
422
  # @param value [true, false, nil]
427
423
  # @return [Chewy::Search::Request]
428
424
  #
@@ -433,7 +429,7 @@ module Chewy
433
429
  # PlacesIndex.search_type(:dfs_query_then_fetch)
434
430
  # # => <PlacesIndex::Query {..., :body=>{:search_type=>"dfs_query_then_fetch"}}>
435
431
  # @see Chewy::Search::Parameters::SearchType
436
- # @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
437
433
  # @param value [String, Symbol]
438
434
  # @return [Chewy::Search::Request]
439
435
  #
@@ -444,7 +440,7 @@ module Chewy
444
440
  # PlacesIndex.preference(:_primary_first)
445
441
  # # => <PlacesIndex::Query {..., :body=>{:preference=>"_primary_first"}}>
446
442
  # @see Chewy::Search::Parameters::Preference
447
- # @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
448
444
  # @param value [String, Symbol]
449
445
  # @return [Chewy::Search::Request]
450
446
  #
@@ -455,7 +451,7 @@ module Chewy
455
451
  # PlacesIndex.timeout('1m')
456
452
  # <PlacesIndex::Query {..., :body=>{:timeout=>"1m"}}>
457
453
  # @see Chewy::Search::Parameters::Timeout
458
- # @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
459
455
  # @param value [String, Symbol]
460
456
  # @return [Chewy::Search::Request]
461
457
  #
@@ -466,7 +462,7 @@ module Chewy
466
462
  # PlacesIndex.limit(10)
467
463
  # <PlacesIndex::Query {..., :body=>{:size=>10}}>
468
464
  # @see Chewy::Search::Parameters::Limit
469
- # @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
470
466
  # @param value [String, Integer]
471
467
  # @return [Chewy::Search::Request]
472
468
  #
@@ -477,7 +473,7 @@ module Chewy
477
473
  # PlacesIndex.offset(10)
478
474
  # <PlacesIndex::Query {..., :body=>{:from=>10}}>
479
475
  # @see Chewy::Search::Parameters::Offset
480
- # @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
481
477
  # @param value [String, Integer]
482
478
  # @return [Chewy::Search::Request]
483
479
  #
@@ -488,7 +484,7 @@ module Chewy
488
484
  # PlacesIndex.terminate_after(10)
489
485
  # <PlacesIndex::Query {..., :body=>{:terminate_after=>10}}>
490
486
  # @see Chewy::Search::Parameters::Offset
491
- # @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
492
488
  # @param value [String, Integer]
493
489
  # @return [Chewy::Search::Request]
494
490
  #
@@ -499,10 +495,32 @@ module Chewy
499
495
  # PlacesIndex.min_score(2)
500
496
  # <PlacesIndex::Query {..., :body=>{:min_score=>2.0}}>
501
497
  # @see Chewy::Search::Parameters::Offset
502
- # @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
503
499
  # @param value [String, Integer, Float]
504
500
  # @return [Chewy::Search::Request]
505
- %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
+ %i[request_cache search_type preference timeout limit offset terminate_after min_score ignore_unavailable collapse].each do |name|
506
524
  define_method name do |value|
507
525
  modify(name) { replace!(value) }
508
526
  end
@@ -511,7 +529,7 @@ module Chewy
511
529
  # @!method source(*values)
512
530
  # Updates `_source` request part. Accepts either an array
513
531
  # of field names/templates or a hash with `includes` and `excludes`
514
- # keys. Source also can be disabled entierly or enabled again.
532
+ # keys. Source also can be disabled entirely or enabled again.
515
533
  #
516
534
  # @example
517
535
  # PlacesIndex.source(:name).source(includes: [:popularity], excludes: :description)
@@ -519,13 +537,13 @@ module Chewy
519
537
  # PlacesIndex.source(false)
520
538
  # # => <PlacesIndex::Query {..., :body=>{:_source=>false}}>
521
539
  # @see Chewy::Search::Parameters::Source
522
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-request-source-filtering.html
540
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html#source-filtering
523
541
  # @param values [true, false, {Symbol => Array<String, Symbol>, String, Symbol}, Array<String, Symbol>, String, Symbol]
524
542
  # @return [Chewy::Search::Request]
525
543
  #
526
544
  # @!method stored_fields(*values)
527
545
  # Updates `stored_fields` request part. Accepts an array of field
528
- # names. Can be entierly disabled and enabled back.
546
+ # names. Can be entirely disabled and enabled back.
529
547
  #
530
548
  # @example
531
549
  # PlacesIndex.stored_fields(:name).stored_fields(:description)
@@ -533,7 +551,7 @@ module Chewy
533
551
  # PlacesIndex.stored_fields(false)
534
552
  # # => <PlacesIndex::Query {..., :body=>{:stored_fields=>"_none_"}}>
535
553
  # @see Chewy::Search::Parameters::StoredFields
536
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-request-stored-fields.html
554
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html#stored-fields
537
555
  # @param values [true, false, String, Symbol, Array<String, Symbol>]
538
556
  # @return [Chewy::Search::Request]
539
557
  %i[source stored_fields].each do |name|
@@ -549,7 +567,7 @@ module Chewy
549
567
  # PlacesIndex.search_after(42, 'Moscow').search_after('London')
550
568
  # # => <PlacesIndex::Query {..., :body=>{:search_after=>["London"]}}>
551
569
  # @see Chewy::Search::Parameters::SearchAfter
552
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-request-search-after.html
570
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#search-after
553
571
  # @param value [Array, Object]
554
572
  # @return [Chewy::Search::Request]
555
573
  def search_after(value, *values)
@@ -557,9 +575,9 @@ module Chewy
557
575
  end
558
576
 
559
577
  # Stores ORM/ODM objects loading options. Options
560
- # might be define per-type or be global, depends on the adapter
578
+ # might be define per-index or be global, depends on the adapter
561
579
  # loading implementation. Also, there are 2 loading options to select
562
- # or exclude types from loading: `only` and `except` respectively.
580
+ # or exclude indexes from loading: `only` and `except` respectively.
563
581
  # Options are updated on further method calls.
564
582
  #
565
583
  # @example
@@ -584,7 +602,7 @@ module Chewy
584
602
  # # "field1"=>{:script=>{:lang=>"painless", :inline=>"some script here"}},
585
603
  # # "field2"=>{:script=>{:lang=>"painless", :inline=>"some script here"}}}}}>
586
604
  # @see Chewy::Search::Parameters::ScriptFields
587
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-request-script-fields.html
605
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html#script-fields
588
606
  # @param value [Hash]
589
607
  # @return [Chewy::Search::Request]
590
608
  #
@@ -596,7 +614,7 @@ module Chewy
596
614
  # PlacesIndex.indices_boost(index1: 1.2, index2: 1.3).indices_boost(index1: 1.5)
597
615
  # # => <PlacesIndex::Query {..., :body=>{:indices_boost=>[{"index2"=>1.3}, {"index1"=>1.5}]}}>
598
616
  # @see Chewy::Search::Parameters::IndicesBoost
599
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-request-index-boost.html
617
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multiple-indices.html#index-boost
600
618
  # @param value [{String, Symbol => String, Integer, Float}]
601
619
  # @return [Chewy::Search::Request]
602
620
  #
@@ -608,7 +626,7 @@ module Chewy
608
626
  # PlacesIndex.rescore(window_size: 100, query: {}).rescore(window_size: 200, query: {})
609
627
  # # => <PlacesIndex::Query {..., :body=>{:rescore=>[{:window_size=>100, :query=>{}}, {:window_size=>200, :query=>{}}]}}>
610
628
  # @see Chewy::Search::Parameters::Rescore
611
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-request-rescore.html
629
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/filter-search-results.html#rescore
612
630
  # @param value [Hash, Array<Hash>]
613
631
  # @return [Chewy::Search::Request]
614
632
  #
@@ -624,7 +642,7 @@ module Chewy
624
642
  # # "fields"=>{:description=>{:type=>"plain"}},
625
643
  # # "pre_tags"=>["<em>"], "post_tags"=>["</em>"]}}}>
626
644
  # @see Chewy::Search::Parameters::Highlight
627
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-request-highlighting.html
645
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/highlighting.html
628
646
  # @param value [Hash]
629
647
  # @return [Chewy::Search::Request]
630
648
  %i[script_fields indices_boost rescore highlight].each do |name|
@@ -647,7 +665,7 @@ module Chewy
647
665
  # # "names"=>{:text=>"tring out Elasticsearch"},
648
666
  # # "descriptions"=>{:text=>"some other text"}}}}>
649
667
  # @see Chewy::Search::Parameters::Suggest
650
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-suggesters.html
668
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html
651
669
  # @param value [Hash]
652
670
  # @return [Chewy::Search::Request]
653
671
  #
@@ -733,7 +751,10 @@ module Chewy
733
751
  # scope1.and(scope2)
734
752
  # # => <PlacesIndex::Query {..., :body=>{:query=>{:bool=>{
735
753
  # # :must=>[{:match=>{:name=>"London"}}, {:match=>{:name=>"Washington"}}],
736
- # # :filter=>{:bool=>{:must=>[{:term=>{:name=>"Moscow"}}, {:bool=>{:must_not=>{:term=>{:name=>"Berlin"}}}}]}}}}}}>
754
+ # # :filter=>{
755
+ # # :bool=>{:must=>[{:term=>{:name=>"Moscow"}}, {:bool=>{:must_not=>{:term=>{:name=>"Berlin"}}}}]}
756
+ # # }
757
+ # # }}}}>
737
758
  # @param other [Chewy::Search::Request] scope to merge
738
759
  # @return [Chewy::Search::Request] new scope
739
760
  #
@@ -750,7 +771,10 @@ module Chewy
750
771
  # scope1.or(scope2)
751
772
  # # => <PlacesIndex::Query {..., :body=>{:query=>{:bool=>{
752
773
  # # :should=>[{:match=>{:name=>"London"}}, {:match=>{:name=>"Washington"}}],
753
- # # :filter=>{:bool=>{:should=>[{:term=>{:name=>"Moscow"}}, {:bool=>{:must_not=>{:term=>{:name=>"Berlin"}}}}]}}}}}}>
774
+ # # :filter=>{
775
+ # # :bool=>{:should=>[{:term=>{:name=>"Moscow"}}, {:bool=>{:must_not=>{:term=>{:name=>"Berlin"}}}}]}
776
+ # # }
777
+ # # }}}}>
754
778
  # @param other [Chewy::Search::Request] scope to merge
755
779
  # @return [Chewy::Search::Request] new scope
756
780
  #
@@ -767,7 +791,13 @@ module Chewy
767
791
  # scope1.not(scope2)
768
792
  # # => <PlacesIndex::Query {..., :body=>{:query=>{:bool=>{
769
793
  # # :must=>{:match=>{:name=>"London"}}, :must_not=>{:match=>{:name=>"Washington"}},
770
- # # :filter=>{:bool=>{:must=>{:term=>{:name=>"Moscow"}}, :must_not=>{:bool=>{:must_not=>{:term=>{:name=>"Berlin"}}}}}}}}}}>
794
+ # # :filter=>{
795
+ # # :bool=>{
796
+ # # :must=>{:term=>{:name=>"Moscow"}},
797
+ # # :must_not=>{:bool=>{:must_not=>{:term=>{:name=>"Berlin"}}}}
798
+ # # }
799
+ # # }
800
+ # # }}}}>
771
801
  # @param other [Chewy::Search::Request] scope to merge
772
802
  # @return [Chewy::Search::Request] new scope
773
803
  %i[and or not].each do |name|
@@ -781,8 +811,8 @@ module Chewy
781
811
  # Returns a new scope containing only specified storages.
782
812
  #
783
813
  # @example
784
- # PlacesIndex.limit(10).offset(10).order(:name).except(:offset, :order)
785
- # # => <PlacesIndex::Query {..., :body=>{:size=>10}}>
814
+ # PlacesIndex.limit(10).offset(10).order(:name).only(:offset, :order)
815
+ # # => <PlacesIndex::Query {..., :body=>{:from=>10, :sort=>["name"]}}>
786
816
  # @param values [Array<String, Symbol>]
787
817
  # @return [Chewy::Search::Request] new scope
788
818
  def only(*values)
@@ -792,8 +822,8 @@ module Chewy
792
822
  # Returns a new scope containing all the storages except specified.
793
823
  #
794
824
  # @example
795
- # PlacesIndex.limit(10).offset(10).order(:name).only(:offset, :order)
796
- # # => <PlacesIndex::Query {..., :body=>{:from=>10, :sort=>["name"]}}>
825
+ # PlacesIndex.limit(10).offset(10).order(:name).except(:offset, :order)
826
+ # # => <PlacesIndex::Query {..., :body=>{:size=>10}}>
797
827
  # @param values [Array<String, Symbol>]
798
828
  # @return [Chewy::Search::Request] new scope
799
829
  def except(*values)
@@ -839,14 +869,14 @@ module Chewy
839
869
  # @overload first
840
870
  # If nothing is passed - it returns a single object.
841
871
  #
842
- # @return [Chewy::Type] result document
872
+ # @return [Chewy::Index] result document
843
873
  #
844
874
  # @overload first(limit)
845
875
  # If limit is provided - it returns the limit amount or less
846
876
  # of wrapper objects.
847
877
  #
848
878
  # @param limit [Integer] amount of requested results
849
- # @return [Array<Chewy::Type>] result document collection
879
+ # @return [Array<Chewy::Index>] result document collection
850
880
  def first(limit = UNDEFINED)
851
881
  request_limit = limit == UNDEFINED ? 1 : limit
852
882
 
@@ -865,7 +895,7 @@ module Chewy
865
895
  # If single id is passed - it returns a single object.
866
896
  #
867
897
  # @param id [Integer, String] id of the desired document
868
- # @return [Chewy::Type] result document
898
+ # @return [Chewy::Index] result document
869
899
  #
870
900
  # @overload find(*ids)
871
901
  # If several field are passed - it returns an array of wrappers.
@@ -873,7 +903,7 @@ module Chewy
873
903
  # batch size - uses scroll API to retrieve everything.
874
904
  #
875
905
  # @param ids [Array<Integer, String>] ids of the desired documents
876
- # @return [Array<Chewy::Type>] result documents
906
+ # @return [Array<Chewy::Index>] result documents
877
907
  def find(*ids)
878
908
  return super if block_given?
879
909
 
@@ -895,7 +925,7 @@ module Chewy
895
925
 
896
926
  # Returns and array of values for specified fields.
897
927
  # Uses `source` to restrict the list of returned fields.
898
- # Fields `_id`, `_type` and `_index` are also supported.
928
+ # Fields `_id`, `_type`, `_routing` and `_index` are also supported.
899
929
  #
900
930
  # @overload pluck(field)
901
931
  # If single field is passed - it returns and array of values.
@@ -928,24 +958,37 @@ module Chewy
928
958
  end
929
959
 
930
960
  # Deletes all the documents from the specified scope it uses
931
- # `delete_by_query` API. For ES < 5.0 it uses `delete_by_query`
932
- # plugin, which requires additional installation effort.
961
+ # `delete_by_query`
933
962
  #
934
963
  # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html
935
- # @see https://www.elastic.co/guide/en/elasticsearch/plugins/2.0/plugins-delete-by-query.html
936
964
  # @note The result hash is different for different API used.
937
- # @param refresh [true, false] field names
965
+ # @param refresh [true, false] Refreshes all shards involved in the delete by query
966
+ # @param wait_for_completion [true, false] wait for request completion or run it asynchronously
967
+ # and return task reference at `.tasks/task/${taskId}`.
968
+ # @param requests_per_second [Float] The throttle for this request in sub-requests per second
969
+ # @param scroll_size [Integer] Size of the scroll request that powers the operation
970
+
938
971
  # @return [Hash] the result of query execution
939
- def delete_all(refresh: true)
940
- request_body = only(WHERE_STORAGES).render.merge(refresh: refresh)
941
- ActiveSupport::Notifications.instrument 'delete_query.chewy',
942
- notification_payload(request: request_body) do
943
- if Runtime.version < '5.0'
944
- delete_by_query_plugin(request_body)
945
- else
946
- Chewy.client.delete_by_query(request_body)
947
- end
948
- end
972
+ def delete_all(refresh: true, wait_for_completion: nil, requests_per_second: nil, scroll_size: nil)
973
+ request_body = only(WHERE_STORAGES).render.merge(
974
+ {
975
+ refresh: refresh,
976
+ wait_for_completion: wait_for_completion,
977
+ requests_per_second: requests_per_second,
978
+ scroll_size: scroll_size
979
+ }.compact
980
+ )
981
+ ActiveSupport::Notifications.instrument 'delete_query.chewy', notification_payload(request: request_body) do
982
+ request_body[:body] = {query: {match_all: {}}} if request_body[:body].empty?
983
+ Chewy.client.delete_by_query(request_body)
984
+ end
985
+ end
986
+
987
+ # Returns whether or not the query has been performed.
988
+ #
989
+ # @return [true, false]
990
+ def performed?
991
+ !@response.nil?
949
992
  end
950
993
 
951
994
  protected
@@ -957,6 +1000,10 @@ module Chewy
957
1000
 
958
1001
  private
959
1002
 
1003
+ def build_response(raw_response)
1004
+ Response.new(raw_response, loader, collection_paginator)
1005
+ end
1006
+
960
1007
  def compare_internals(other)
961
1008
  parameters == other.parameters
962
1009
  end
@@ -975,21 +1022,17 @@ module Chewy
975
1022
 
976
1023
  def perform(additional = {})
977
1024
  request_body = render.merge(additional)
978
- ActiveSupport::Notifications.instrument 'search_query.chewy',
979
- notification_payload(request: request_body) do
980
- begin
981
- Chewy.client.search(request_body)
982
- rescue Elasticsearch::Transport::Transport::Errors::NotFound
983
- {}
984
- end
985
- end
1025
+ ActiveSupport::Notifications.instrument 'search_query.chewy', notification_payload(request: request_body) do
1026
+ Chewy.client.search(request_body)
1027
+ rescue Elasticsearch::Transport::Transport::Errors::NotFound
1028
+ {}
1029
+ end
986
1030
  end
987
1031
 
988
1032
  def notification_payload(additional)
989
1033
  {
990
- indexes: _indices, types: _types,
991
- index: _indices.one? ? _indices.first : _indices,
992
- type: _types.one? ? _types.first : _types
1034
+ indexes: _indices,
1035
+ index: _indices.one? ? _indices.first : _indices
993
1036
  }.merge(additional)
994
1037
  end
995
1038
 
@@ -997,10 +1040,6 @@ module Chewy
997
1040
  parameters[:indices].indices
998
1041
  end
999
1042
 
1000
- def _types
1001
- parameters[:indices].types
1002
- end
1003
-
1004
1043
  def raw_limit_value
1005
1044
  parameters[:limit].value
1006
1045
  end
@@ -1009,15 +1048,6 @@ module Chewy
1009
1048
  parameters[:offset].value
1010
1049
  end
1011
1050
 
1012
- def delete_by_query_plugin(request)
1013
- path = Elasticsearch::API::Utils.__pathify(
1014
- Elasticsearch::API::Utils.__listify(request[:index]),
1015
- Elasticsearch::API::Utils.__listify(request[:type]),
1016
- '_query'
1017
- )
1018
- Chewy.client.perform_request(Elasticsearch::API::HTTP_DELETE, path, {}, request[:body]).body
1019
- end
1020
-
1021
1051
  def loader
1022
1052
  @loader ||= Loader.new(
1023
1053
  indexes: parameters[:indices].indices,
@@ -1033,10 +1063,6 @@ module Chewy
1033
1063
  end
1034
1064
  end
1035
1065
 
1036
- def performed?
1037
- !@response.nil?
1038
- end
1039
-
1040
1066
  def collection_paginator
1041
1067
  method(:paginated_collection).to_proc if respond_to?(:paginated_collection, true)
1042
1068
  end