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