diff --git a/CHANGELOG.md b/CHANGELOG.md index c445bb9..bf83719 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Added `wait` option to async reindex - Added `model_includes` option - Raise error for `reindex_status` when Redis not configured +- Warn when incompatible options used with `body` option ## 2.3.1 diff --git a/lib/searchkick/index.rb b/lib/searchkick/index.rb index 1260d86..469c692 100644 --- a/lib/searchkick/index.rb +++ b/lib/searchkick/index.rb @@ -298,8 +298,8 @@ module Searchkick scope = scope.select("id").except(:includes, :preload) if async - scope.find_in_batches batch_size: batch_size do |batch| - import_or_update batch, method_name, async + scope.find_in_batches batch_size: batch_size do |items| + import_or_update items, method_name, async end else each_batch(scope) do |items| diff --git a/lib/searchkick/query.rb b/lib/searchkick/query.rb index 6c72932..22a270b 100644 --- a/lib/searchkick/query.rb +++ b/lib/searchkick/query.rb @@ -223,6 +223,11 @@ module Searchkick @json = options[:body] if @json + ignored_options = options.keys & [:aggs, :boost, + :boost_by, :boost_by_distance, :boost_where, :conversions, :conversions_term, :exclude, :explain, + :fields, :highlight, :indices_boost, :limit, :match, :misspellings, :offset, :operator, :order, + :padding, :page, :per_page, :select, :smart_aggs, :suggest, :where] + warn "The body option replaces the entire body, so the following options are ignored: #{ignored_options.join(", ")}" if ignored_options.any? payload = @json else if options[:similar] @@ -473,15 +478,16 @@ module Searchkick elsif load payload[:_source] = false end + end - if options[:type] || (klass != searchkick_klass && searchkick_index) - @type = [options[:type] || klass].flatten.map { |v| searchkick_index.klass_document_type(v) } - end - - # routing - @routing = options[:routing] if options[:routing] + # type + if options[:type] || (klass != searchkick_klass && searchkick_index) + @type = [options[:type] || klass].flatten.map { |v| searchkick_index.klass_document_type(v) } end + # routing + @routing = options[:routing] if options[:routing] + # merge more body options payload = payload.deep_merge(options[:body_options]) if options[:body_options] diff --git a/test/index_test.rb b/test/index_test.rb index 403925e..d53efc7 100644 --- a/test/index_test.rb +++ b/test/index_test.rb @@ -59,6 +59,10 @@ class IndexTest < Minitest::Test assert_equal ["Dollar Tree"], Store.search(body: {query: {match: {name: "Dollar Tree"}}}, load: false).map(&:name) end + def test_body_warning + 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}) } + end + def test_block store_names ["Dollar Tree"] products = -- libgit2 0.21.0