Getting a FrozenError running SearchKick reindex with ElasticSearch

software engineering Oct 5, 2019

I’ve started to play with SearchKick again as a new component to my pet project and I kept hitting a FrozenError message whenever I ran the re-index call

Traceback (most recent call last):
        1: from (irb):1
FrozenError (can't modify frozen String)

After running a trace, I found the following things:

** Invoke searchkick:reindex (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute searchkick:reindex
rake aborted!
FrozenError: can't modify frozen String
/Users/kelvin/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/elasticsearch-transport-7.3.0/lib/elasticsearch/transport/transport/response.rb:19:in `force_encoding'
/Users/kelvin/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/elasticsearch-transport-7.3.0/lib/elasticsearch/transport/transport/response.rb:19:in `initialize'
/Users/kelvin/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/elasticsearch-transport-7.3.0/lib/elasticsearch/transport/transport/http/faraday.rb:32:in `new'
/Users/kelvin/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/elasticsearch-transport-7.3.0/lib/elasticsearch/transport/transport/http/faraday.rb:32:in `block in perform_request'
/Users/kelvin/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/elasticsearch-transport-7.3.0/lib/elasticsearch/transport/transport/base.rb:268:in `perform_request'
/Users/kelvin/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/elasticsearch-transport-7.3.0/lib/elasticsearch/transport/transport/http/faraday.rb:24:in `perform_request'
/Users/kelvin/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/elasticsearch-transport-7.3.0/lib/elasticsearch/transport/client.rb:152:in `perform_request'
/Users/kelvin/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/elasticsearch-api-7.3.0/lib/elasticsearch/api/namespace/common.rb:25:in `perform_request'
/Users/kelvin/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/elasticsearch-api-7.3.0/lib/elasticsearch/api/actions/indices/exists_alias.rb:40:in `block in exists_alias'
/Users/kelvin/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/elasticsearch-api-7.3.0/lib/elasticsearch/api/utils.rb:206:in `__rescue_from_not_found'
/Users/kelvin/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/elasticsearch-api-7.3.0/lib/elasticsearch/api/actions/indices/exists_alias.rb:39:in `exists_alias'
/Users/kelvin/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/searchkick-4.1.0/lib/searchkick/index.rb:38:in `alias_exists?'
/Users/kelvin/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/searchkick-4.1.0/lib/searchkick/index.rb:20:in `delete'
/Users/kelvin/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/searchkick-4.1.0/lib/searchkick/index.rb:121:in `block in clean_indices'
/Users/kelvin/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/searchkick-4.1.0/lib/searchkick/index.rb:120:in `each'
/Users/kelvin/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/searchkick-4.1.0/lib/searchkick/index.rb:120:in `clean_indices'
/Users/kelvin/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/searchkick-4.1.0/lib/searchkick/index.rb:274:in `reindex_scope'
/Users/kelvin/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/searchkick-4.1.0/lib/searchkick/index.rb:200:in `reindex'
/Users/kelvin/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/searchkick-4.1.0/lib/searchkick/model.rb:60:in `searchkick_reindex'
/Users/kelvin/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/searchkick-4.1.0/lib/tasks/searchkick.rake:7:in `block (2 levels) in <top (required)>'

After doing some research, it turns out that the issue is with Faraday. Once I downgraded it to version 0.15.4, the error was resolved. To do that, I modified the Gemfile to have the following line:

gem 'faraday', '~> 0.15.4'

Now, I’m on my way to implement Searchkick for my project

Tags

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.