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
- Fix a race condition during reindex As outlined in https://github.com/ankane/searchkick/issues/843 reindexing may sometimes fail with 'index_already_exists_exception'. This primitive patch fixes it ... — committed to kakra/searchkick by kakra 7 years ago
- Fix a race condition during reindex As outlined in https://github.com/ankane/searchkick/issues/843 reindexing may sometimes fail with 'index_already_exists_exception'. This primitive patch fixes it ... — committed to kakra/searchkick by kakra 7 years ago
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.
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
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: