Commit 4e0a794044d14ee5ce3a91ffa94043db992a71a9

Authored by Andrew Kane
1 parent ee761d52

Fixed custom mappings - fixes #1272 closes #1271

Co-authored-by: Stanislav Kravtsov <my-blizz4rd@hotmail.com>
1 ## 4.0.2 [unreleased] 1 ## 4.0.2 [unreleased]
2 2
3 - Added block form of `scroll` 3 - Added block form of `scroll`
  4 +- Fixed custom mappings
4 5
5 ## 4.0.1 6 ## 4.0.1
6 7
lib/searchkick/index_options.rb
@@ -13,7 +13,7 @@ module Searchkick @@ -13,7 +13,7 @@ module Searchkick
13 index_type = index_type.call if index_type.respond_to?(:call) 13 index_type = index_type.call if index_type.respond_to?(:call)
14 end 14 end
15 15
16 - custom_mapping = options[:mapping] || {} 16 + custom_mapping = options[:mappings] || {}
17 if below70 && custom_mapping.keys.map(&:to_sym).include?(:properties) 17 if below70 && custom_mapping.keys.map(&:to_sym).include?(:properties)
18 # add type 18 # add type
19 custom_mapping = {index_type => custom_mapping} 19 custom_mapping = {index_type => custom_mapping}
test/errors_test.rb
@@ -9,7 +9,6 @@ class ErrorsTest &lt; Minitest::Test @@ -9,7 +9,6 @@ class ErrorsTest &lt; Minitest::Test
9 name: {type: "date"} 9 name: {type: "date"}
10 } 10 }
11 } 11 }
12 - mapping = {product: mapping} if Searchkick.server_below?("7.0.0")  
13 index = Searchkick::Index.new "dogs", mappings: mapping 12 index = Searchkick::Index.new "dogs", mappings: mapping
14 index.delete if index.exists? 13 index.delete if index.exists?
15 index.create_index 14 index.create_index
test/index_test.rb
@@ -47,10 +47,12 @@ class IndexTest &lt; Minitest::Test @@ -47,10 +47,12 @@ class IndexTest &lt; Minitest::Test
47 assert_equal 1, Product.searchkick_index.total_docs 47 assert_equal 1, Product.searchkick_index.total_docs
48 end 48 end
49 49
50 - def test_mapping 50 + def test_mappings
51 store_names ["Dollar Tree"], Store 51 store_names ["Dollar Tree"], Store
52 - assert_equal [], Store.search(body: {query: {match: {name: "dollar"}}}).map(&:name)  
53 - assert_equal ["Dollar Tree"], Store.search(body: {query: {match: {name: "Dollar Tree"}}}).map(&:name) 52 + assert_equal ["Dollar Tree"], Store.search(body: {query: {match: {name: "dollar"}}}).map(&:name)
  53 + mapping = Store.search_index.mapping.values.first["mappings"]
  54 + mapping = mapping["store"] if Searchkick.server_below?("7.0.0")
  55 + assert_equal "text", mapping["properties"]["name"]["type"]
54 end 56 end
55 57
56 def test_body 58 def test_body
test/models/store.rb
1 class Store 1 class Store
2 mappings = { 2 mappings = {
3 properties: { 3 properties: {
4 - name: {type: "keyword"} 4 + name: {type: "text"}
5 } 5 }
6 } 6 }
7 7