Commit 73dfbde49d67050d578ca804a1fc8d00854218af
1 parent
cb63edde
Exists in
master
and in
19 other branches
Warn when incompatible options used with body option - for #984
Showing
4 changed files
with
19 additions
and
8 deletions
Show diff stats
CHANGELOG.md
lib/searchkick/index.rb
... | ... | @@ -298,8 +298,8 @@ module Searchkick |
298 | 298 | |
299 | 299 | scope = scope.select("id").except(:includes, :preload) if async |
300 | 300 | |
301 | - scope.find_in_batches batch_size: batch_size do |batch| | |
302 | - import_or_update batch, method_name, async | |
301 | + scope.find_in_batches batch_size: batch_size do |items| | |
302 | + import_or_update items, method_name, async | |
303 | 303 | end |
304 | 304 | else |
305 | 305 | each_batch(scope) do |items| | ... | ... |
lib/searchkick/query.rb
... | ... | @@ -223,6 +223,11 @@ module Searchkick |
223 | 223 | |
224 | 224 | @json = options[:body] |
225 | 225 | if @json |
226 | + ignored_options = options.keys & [:aggs, :boost, | |
227 | + :boost_by, :boost_by_distance, :boost_where, :conversions, :conversions_term, :exclude, :explain, | |
228 | + :fields, :highlight, :indices_boost, :limit, :match, :misspellings, :offset, :operator, :order, | |
229 | + :padding, :page, :per_page, :select, :smart_aggs, :suggest, :where] | |
230 | + warn "The body option replaces the entire body, so the following options are ignored: #{ignored_options.join(", ")}" if ignored_options.any? | |
226 | 231 | payload = @json |
227 | 232 | else |
228 | 233 | if options[:similar] |
... | ... | @@ -473,15 +478,16 @@ module Searchkick |
473 | 478 | elsif load |
474 | 479 | payload[:_source] = false |
475 | 480 | end |
481 | + end | |
476 | 482 | |
477 | - if options[:type] || (klass != searchkick_klass && searchkick_index) | |
478 | - @type = [options[:type] || klass].flatten.map { |v| searchkick_index.klass_document_type(v) } | |
479 | - end | |
480 | - | |
481 | - # routing | |
482 | - @routing = options[:routing] if options[:routing] | |
483 | + # type | |
484 | + if options[:type] || (klass != searchkick_klass && searchkick_index) | |
485 | + @type = [options[:type] || klass].flatten.map { |v| searchkick_index.klass_document_type(v) } | |
483 | 486 | end |
484 | 487 | |
488 | + # routing | |
489 | + @routing = options[:routing] if options[:routing] | |
490 | + | |
485 | 491 | # merge more body options |
486 | 492 | payload = payload.deep_merge(options[:body_options]) if options[:body_options] |
487 | 493 | ... | ... |
test/index_test.rb
... | ... | @@ -59,6 +59,10 @@ class IndexTest < Minitest::Test |
59 | 59 | assert_equal ["Dollar Tree"], Store.search(body: {query: {match: {name: "Dollar Tree"}}}, load: false).map(&:name) |
60 | 60 | end |
61 | 61 | |
62 | + def test_body_warning | |
63 | + assert_output(nil, "The body option replaces the entire body, so the following options are ignored: where\n") { Store.search(body: {query: {match: {name: "dollar"}}}, where: {id: 1}) } | |
64 | + end | |
65 | + | |
62 | 66 | def test_block |
63 | 67 | store_names ["Dollar Tree"] |
64 | 68 | products = | ... | ... |