searchkick: Reindex of Collection gives Elasticsearch Transport error

Hello,

I have a model with name Actor.And the model looks like the following snippet

class Actor 
      include Mongoid::Document  
      field :name, type: String 
      field :birthName, as: :birth_name, type: String 
      field :date_of_birth, type: Date 
      field :height, type: Measurement 
      field :bio, type: String 
    searchkick
end

when I try to reindex my model using Actor.reindex. I am getting the following error which shows the root cause as Index already exists.

irb(main):001:0> Actor.reindex
Elasticsearch::Transport::Transport::Errors::BadRequest: [400] {"error":{"root_cause":[{"type":"index_already_exists_exception","reason":"index [actors_development_20170209175219593/TKOPkMY1TsGNEYmWlVCKo
A] already exists","index_uuid":"TKOPkMY1TsGNEYmWlVCKoA","index":"actors_development_20170209175219593"}],"type":"index_already_exists_exception","reason":"index [actors_development_20170209175219593/TKO
PkMY1TsGNEYmWlVCKoA] already exists","index_uuid":"TKOPkMY1TsGNEYmWlVCKoA","index":"actors_development_20170209175219593"},"status":400}
        from /home/ravi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/elasticsearch-transport-5.0.1/lib/elasticsearch/transport/transport/base.rb:201:in `__raise_transport_error'
        from /home/ravi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/elasticsearch-transport-5.0.1/lib/elasticsearch/transport/transport/base.rb:318:in `perform_request'
        from /home/ravi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/elasticsearch-transport-5.0.1/lib/elasticsearch/transport/transport/http/faraday.rb:20:in `perform_request'
        from /home/ravi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/elasticsearch-transport-5.0.1/lib/elasticsearch/transport/client.rb:128:in `perform_request'
        from /home/ravi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/elasticsearch-api-5.0.1/lib/elasticsearch/api/namespace/common.rb:21:in `perform_request'
        from /home/ravi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/elasticsearch-api-5.0.1/lib/elasticsearch/api/actions/indices/create.rb:86:in `create'
        from /home/ravi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/searchkick-2.1.1/lib/searchkick/index.rb:14:in `create'
        from /home/ravi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/searchkick-2.1.1/lib/searchkick/index.rb:177:in `create_index'
        from /home/ravi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/searchkick-2.1.1/lib/searchkick/index.rb:226:in `reindex_scope'
        from /home/ravi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/searchkick-2.1.1/lib/searchkick/model.rb:70:in `searchkick_reindex'
        from (irb):1
        from /home/ravi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/commands/console.rb:110:in `start'
        from /home/ravi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/commands/console.rb:9:in `start'
        from /home/ravi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:68:in `console'
        from /home/ravi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
        from /home/ravi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/commands.rb:17:in `<top (required)>'from bin/rails:4:in `require'

Since the error is showing Index already exists, then I deleted the index from elasticsearch and tried to run again.But, it is giving me the same error index already exists

Can anyone please help to find the reason behind this error

Thanks, Ravi.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (2 by maintainers)

Commits related to this issue

Most upvoted comments

I’m seeing this, too… Running “rake searchkick:reindex:all” always produces this issue with one of the models, not necessarily the same on successive runs. Running “Model.reindex” in a rails console almost never produces this issue for me. It seems like there’s some timing or locking issue involved, and such a race condition should be fixed.

This happened only after I was forced to upgrade ElasticSearch. So the different behavior is probably in ElasticSearch but I’m confident it’s still a bug that should be fixed in Searchkick because it should not depend on specific behavior of very specific ES versions.

Reindexing User...
rake aborted!
Elasticsearch::Transport::Transport::Errors::BadRequest: [400] {"error":{"root_cause":[{"type":"index_already_exists_exception","reason":"index [sbcms_development_users_20171201121205965/-xEONhgRRAmsAUYuW4423g] already exists","index_uuid":"-xEONhgRRAmsAUYuW4423g","index":"sbcms_development_users_20171201121205965"}],"type":"index_already_exists_exception","reason":"index [sbcms_development_users_20171201121205965/-xEONhgRRAmsAUYuW4423g] already exists","index_uuid":"-xEONhgRRAmsAUYuW4423g","index":"sbcms_development_users_20171201121205965"},"status":400}
/home/kakra/.rvm/gems/ruby-2.2.5/gems/elasticsearch-transport-6.0.0/lib/elasticsearch/transport/transport/base.rb:202:in `__raise_transport_error'
/home/kakra/.rvm/gems/ruby-2.2.5/gems/elasticsearch-transport-6.0.0/lib/elasticsearch/transport/transport/base.rb:319:in `perform_request'
/home/kakra/.rvm/gems/ruby-2.2.5/gems/elasticsearch-transport-6.0.0/lib/elasticsearch/transport/transport/http/faraday.rb:20:in `perform_request'
/home/kakra/.rvm/gems/ruby-2.2.5/gems/elasticsearch-transport-6.0.0/lib/elasticsearch/transport/client.rb:131:in `perform_request'
/home/kakra/.rvm/gems/ruby-2.2.5/gems/elasticsearch-api-6.0.0/lib/elasticsearch/api/namespace/common.rb:21:in `perform_request'
/home/kakra/.rvm/gems/ruby-2.2.5/gems/elasticsearch-api-6.0.0/lib/elasticsearch/api/actions/indices/create.rb:86:in `create'
/home/kakra/.rvm/gems/ruby-2.2.5/gems/searchkick-1.5.1/lib/searchkick/index.rb:13:in `create'
/home/kakra/.rvm/gems/ruby-2.2.5/gems/searchkick-1.5.1/lib/searchkick/index.rb:151:in `create_index'
/home/kakra/.rvm/gems/ruby-2.2.5/gems/searchkick-1.5.1/lib/searchkick/index.rb:201:in `reindex_scope'
/home/kakra/.rvm/gems/ruby-2.2.5/gems/searchkick-1.5.1/lib/searchkick/model.rb:58:in `searchkick_reindex'
/home/kakra/.rvm/gems/ruby-2.2.5/gems/searchkick-1.5.1/lib/searchkick/tasks.rb:26:in `block (4 levels) in <top (required)>'
/home/kakra/.rvm/gems/ruby-2.2.5/gems/searchkick-1.5.1/lib/searchkick/tasks.rb:24:in `each'
/home/kakra/.rvm/gems/ruby-2.2.5/gems/searchkick-1.5.1/lib/searchkick/tasks.rb:24:in `block (3 levels) in <top (required)>'
/home/kakra/.rvm/gems/ruby-2.2.5/gems/bundler-1.16.0/lib/bundler/cli/exec.rb:75:in `load'
/home/kakra/.rvm/gems/ruby-2.2.5/gems/bundler-1.16.0/lib/bundler/cli/exec.rb:75:in `kernel_load'
/home/kakra/.rvm/gems/ruby-2.2.5/gems/bundler-1.16.0/lib/bundler/cli/exec.rb:28:in `run'
/home/kakra/.rvm/gems/ruby-2.2.5/gems/bundler-1.16.0/lib/bundler/cli.rb:424:in `exec'
/home/kakra/.rvm/gems/ruby-2.2.5/gems/bundler-1.16.0/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/home/kakra/.rvm/gems/ruby-2.2.5/gems/bundler-1.16.0/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/home/kakra/.rvm/gems/ruby-2.2.5/gems/bundler-1.16.0/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/home/kakra/.rvm/gems/ruby-2.2.5/gems/bundler-1.16.0/lib/bundler/cli.rb:27:in `dispatch'
/home/kakra/.rvm/gems/ruby-2.2.5/gems/bundler-1.16.0/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/home/kakra/.rvm/gems/ruby-2.2.5/gems/bundler-1.16.0/lib/bundler/cli.rb:18:in `start'
/home/kakra/.rvm/gems/ruby-2.2.5/gems/bundler-1.16.0/exe/bundle:30:in `block in <top (required)>'
/home/kakra/.rvm/gems/ruby-2.2.5/gems/bundler-1.16.0/lib/bundler/friendly_errors.rb:122:in `with_friendly_errors'
/home/kakra/.rvm/gems/ruby-2.2.5/gems/bundler-1.16.0/exe/bundle:22:in `<top (required)>'
/home/kakra/.rvm/gems/ruby-2.2.5/bin/bundle:23:in `load'
/home/kakra/.rvm/gems/ruby-2.2.5/bin/bundle:23:in `<main>'
/home/kakra/.rvm/gems/ruby-2.2.5/bin/ruby_executable_hooks:15:in `eval'
/home/kakra/.rvm/gems/ruby-2.2.5/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => searchkick:reindex:all
(See full trace by running task with --trace)

I also got the same error in 2.5.0. It is time to take a time-consuming case (for example, specifying a huge number of lines of synonym file) when creating index with PUT request.

In elasticsearch-ruby, host_unreachable_exceptions occurred and retry processing was done.

https://github.com/elastic/elasticsearch-ruby/blob/master/elasticsearch-transport/lib/elasticsearch/transport/transport/base.rb#L293

rescue * host_unreachable_exceptions => e
        logger.error "[# {e.class}] # {e.message} # {connection.host.inspect}" if logger

        connection.dead!

        if @options [: reload_on_failure] and tries <connections.all.size
          logger.warn "[# {e.class}] Reloading connections (attempt # {tries} of # {connections.all.size})" if logger
          reload_connections! and retry
        end

I avoided it by extending the timeout. SearchkickTimeout = 120

I disabled shard allocation and forgot to re-enable it (during an upgrade), and I was getting the same errors as above. Ya’ll might be running into the same problem.

How to resolve:

curl -XPUT 'localhost:9200/_cluster/settings' -d '{
    "transient" : {
        "cluster.routing.allocation.enable" : "all"
    }
}'