Commit b3bb13f2ab4b79d7bf4a1e3c7efd40e55e1b3eb4

Authored by Andrew
1 parent af84197c

Friendlier error message for bad mapping with partial matches - fixes #1127

CHANGELOG.md
  1 +## 3.0.4 [unreleased]
  2 +
  3 +- Friendlier error message for bad mapping with partial matches
  4 +
1 5 ## 3.0.3
2 6  
3 7 - Added support for pagination with `body` option
... ...
lib/searchkick/query.rb
... ... @@ -188,7 +188,7 @@ module Searchkick
188 188 )
189 189  
190 190 raise UnsupportedVersionError, "This version of Searchkick requires Elasticsearch 5 or greater"
191   - elsif e.message.include?("[multi_match] analyzer [searchkick_search] not found")
  191 + elsif e.message =~ /analyzer \[searchkick_.+\] not found/
192 192 raise InvalidQueryError, "Bad mapping - run #{reindex_command}"
193 193 else
194 194 raise InvalidQueryError, e.message
... ...
test/index_test.rb
... ... @@ -93,7 +93,8 @@ class IndexTest < Minitest::Test
93 93 def test_bad_mapping
94 94 Product.searchkick_index.delete
95 95 store_names ["Product A"]
96   - assert_raises(Searchkick::InvalidQueryError) { Product.search "test" }
  96 + error = assert_raises(Searchkick::InvalidQueryError) { Product.search "test" }
  97 + assert_equal "Bad mapping - run Product.reindex", error.message
97 98 ensure
98 99 Product.reindex
99 100 end
... ...