Commit e0cf73d28a9683040f84b2717f9341dd5dcaa2d6

Authored by Andrew Kane
1 parent 8ed1eacb

Added custom message for bad mapping for #199

Showing 2 changed files with 13 additions and 1 deletions   Show diff stats
lib/searchkick/query.rb
... ... @@ -338,7 +338,11 @@ module Searchkick
338 338  
339 339 raise UnsupportedVersionError, "This version of Searchkick requires Elasticsearch 0.90.4 or greater"
340 340 elsif status_code == 400
341   - raise InvalidQueryError, e.message
  341 + if e.message.include?("[multi_match] analyzer [searchkick_search] not found")
  342 + raise InvalidQueryError, "Bad mapping - run #{searchkick_klass.name}.reindex"
  343 + else
  344 + raise InvalidQueryError, e.message
  345 + end
342 346 else
343 347 raise e
344 348 end
... ...
test/index_test.rb
... ... @@ -41,6 +41,14 @@ class TestIndex < Minitest::Unit::TestCase
41 41 assert_search "product", ["Product B"]
42 42 end
43 43  
  44 + def test_bad_mapping
  45 + Product.searchkick_index.delete
  46 + store_names ["Product A"]
  47 + assert_raises(Searchkick::InvalidQueryError){ Product.search "test" }
  48 + ensure
  49 + Product.reindex
  50 + end
  51 +
44 52 def test_missing_index
45 53 assert_raises(Searchkick::MissingIndexError){ Product.search "test", index_name: "not_found" }
46 54 end
... ...