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
@@ -5,6 +5,7 @@ | @@ -5,6 +5,7 @@ | ||
5 | - Added `wait` option to async reindex | 5 | - Added `wait` option to async reindex |
6 | - Added `model_includes` option | 6 | - Added `model_includes` option |
7 | - Raise error for `reindex_status` when Redis not configured | 7 | - Raise error for `reindex_status` when Redis not configured |
8 | +- Warn when incompatible options used with `body` option | ||
8 | 9 | ||
9 | ## 2.3.1 | 10 | ## 2.3.1 |
10 | 11 |
lib/searchkick/index.rb
@@ -298,8 +298,8 @@ module Searchkick | @@ -298,8 +298,8 @@ module Searchkick | ||
298 | 298 | ||
299 | scope = scope.select("id").except(:includes, :preload) if async | 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 | end | 303 | end |
304 | else | 304 | else |
305 | each_batch(scope) do |items| | 305 | each_batch(scope) do |items| |
lib/searchkick/query.rb
@@ -223,6 +223,11 @@ module Searchkick | @@ -223,6 +223,11 @@ module Searchkick | ||
223 | 223 | ||
224 | @json = options[:body] | 224 | @json = options[:body] |
225 | if @json | 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 | payload = @json | 231 | payload = @json |
227 | else | 232 | else |
228 | if options[:similar] | 233 | if options[:similar] |
@@ -473,15 +478,16 @@ module Searchkick | @@ -473,15 +478,16 @@ module Searchkick | ||
473 | elsif load | 478 | elsif load |
474 | payload[:_source] = false | 479 | payload[:_source] = false |
475 | end | 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 | end | 486 | end |
484 | 487 | ||
488 | + # routing | ||
489 | + @routing = options[:routing] if options[:routing] | ||
490 | + | ||
485 | # merge more body options | 491 | # merge more body options |
486 | payload = payload.deep_merge(options[:body_options]) if options[:body_options] | 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,6 +59,10 @@ class IndexTest < Minitest::Test | ||
59 | assert_equal ["Dollar Tree"], Store.search(body: {query: {match: {name: "Dollar Tree"}}}, load: false).map(&:name) | 59 | assert_equal ["Dollar Tree"], Store.search(body: {query: {match: {name: "Dollar Tree"}}}, load: false).map(&:name) |
60 | end | 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 | def test_block | 66 | def test_block |
63 | store_names ["Dollar Tree"] | 67 | store_names ["Dollar Tree"] |
64 | products = | 68 | products = |