Monroe Mann
Monroe Mann

Reputation: 625

Heroku Searchkick Error: Elasticsearch::UnsupportedProductError (The client noticed that the server is not a supported distribution of Elasticsearch.)

Stack Ruby on Rails 7, Search Kick, Elasticsearch, Bonsai, Heroku

Issue Every time I try to create a new contact, I get this error in the rails log--tail output:

Error Message

[c6d3f6d0-156c-4546-a7e8-5175d14c6835] Completed 500 Internal Server Error in 78ms (Searchkick: 16.2ms | ActiveRecord: 38.6ms | Allocations: 14934)
2024-04-18T13:37:40.040852+00:00 app[web.1]: F, [2024-04-18T13:37:40.040771 #2] FATAL -- : [c6d3f6d0-156c-4546-a7e8-5175d14c6835]
2024-04-18T13:37:40.040853+00:00 app[web.1]: [c6d3f6d0-156c-4546-a7e8-5175d14c6835] Elasticsearch::UnsupportedProductError (The client noticed that the server is not a supported distribution of Elasticsearch.):

SearchKick.rb Initializer

if Rails.env == 'production'
  url = ENV["BONSAI_URL"]
  transport_options = { request: { timeout: 250 } }
  options = { hosts: url, retry_on_failure: true, transport_options: transport_options }
  Searchkick.client = Elasticsearch::Client.new(options)
end

Gemfile gem 'ransack' gem 'searchkick' gem 'elasticsearch', '~>7.17'

Upvotes: 0

Views: 76

Answers (1)

Monroe Mann
Monroe Mann

Reputation: 625

Here is a solution that ultimately worked for me:

I found a partial solution based on one website recommended to me by @dbugger:

https://medium.com/@nerboda/integrating-elastic-search-with-rails-on-heroku-using-searchkick-and-bonsai-eb1aebbc6df7

and another partial solution in a similar Stack Overflow post:

Elasticsearch::UnsupportedProductError (The client noticed that the server is not a supported distribution of Elasticsearch

Together, these two resources helped me to solve this issue.

First, elasticsearch 7.17 was causing the main error. I had to change the gemfile to read as follows:

gem 'elasticsearch', '< 7.14'

That solved that initial error. If you read the stack overflow post above that I shared, you will understand why.

But then another error appeared about an index not being available:

Searchkick::ImportError ({"type"=>"index_not_found_exception", "reason"=>"no such index [contacts_production] and [action.auto_create_index] 

I then had to run:

heroku run rails searchkick:reindex CLASS=Contact

I found this solution on the website that @dbugger shared with me.

Note that in the above command, you have to change the class to whatever class is being impacted by the search. In the example website above, it has CLASS=Listing. I initially didn't realize that, and received errors trying to create an index for a model that didn't exist. You have to change that above command to reflect the model name of what you are searching over.

After doing the above, and pushing to Heroku, the error disappeared, and I was able to successfully create a contact.

Upvotes: 0

Related Questions