diff --git a/CHANGELOG.md b/CHANGELOG.md index ed3ac80..fa173bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 4.0.2 [unreleased] - Added block form of `scroll` +- Fixed custom mappings ## 4.0.1 diff --git a/lib/searchkick/index_options.rb b/lib/searchkick/index_options.rb index df2e0b9..b83360a 100644 --- a/lib/searchkick/index_options.rb +++ b/lib/searchkick/index_options.rb @@ -13,7 +13,7 @@ module Searchkick index_type = index_type.call if index_type.respond_to?(:call) end - custom_mapping = options[:mapping] || {} + custom_mapping = options[:mappings] || {} if below70 && custom_mapping.keys.map(&:to_sym).include?(:properties) # add type custom_mapping = {index_type => custom_mapping} diff --git a/test/errors_test.rb b/test/errors_test.rb index bb08321..7b991af 100644 --- a/test/errors_test.rb +++ b/test/errors_test.rb @@ -9,7 +9,6 @@ class ErrorsTest < Minitest::Test name: {type: "date"} } } - mapping = {product: mapping} if Searchkick.server_below?("7.0.0") index = Searchkick::Index.new "dogs", mappings: mapping index.delete if index.exists? index.create_index diff --git a/test/index_test.rb b/test/index_test.rb index 97041cc..802701b 100644 --- a/test/index_test.rb +++ b/test/index_test.rb @@ -47,10 +47,12 @@ class IndexTest < Minitest::Test assert_equal 1, Product.searchkick_index.total_docs end - def test_mapping + def test_mappings store_names ["Dollar Tree"], Store - assert_equal [], Store.search(body: {query: {match: {name: "dollar"}}}).map(&:name) - assert_equal ["Dollar Tree"], Store.search(body: {query: {match: {name: "Dollar Tree"}}}).map(&:name) + assert_equal ["Dollar Tree"], Store.search(body: {query: {match: {name: "dollar"}}}).map(&:name) + mapping = Store.search_index.mapping.values.first["mappings"] + mapping = mapping["store"] if Searchkick.server_below?("7.0.0") + assert_equal "text", mapping["properties"]["name"]["type"] end def test_body diff --git a/test/models/store.rb b/test/models/store.rb index 78bfbc2..a47c114 100644 --- a/test/models/store.rb +++ b/test/models/store.rb @@ -1,7 +1,7 @@ class Store mappings = { properties: { - name: {type: "keyword"} + name: {type: "text"} } } -- libgit2 0.21.0