When "Add data to the search index", I run "Job. reindex" in rails c, then return an error as follows.
apple@apple-2 ⮀ ~/rails/job-listing1129 ⮀ â master± ⮀ rails c
Running via Spring preloader in process 4765
Loading development environment (Rails 5.0.6)
2.3.1 :001 > Job.reindex
Job Load (0.4ms) SELECT "jobs".* FROM "jobs" ORDER BY "jobs"."id" ASC LIMIT ? [["LIMIT", 1000]]
Elasticsearch::Transport::Transport::Errors::Forbidden: [403] {"error":{"root_cause":[{"type":"cluster_block_exception","reason":"blocked by: [FORBIDDEN/12/index read-only / allow delete (api)];"}],"type":"cluster_block_exception","reason":"blocked by: [FORBIDDEN/12/index read-only / allow delete (api)];"},"status":403}
from /Users/apple/.rvm/gems/ruby-2.3.1/gems/elasticsearch-transport-6.0.0/lib/elasticsearch/transport/transport/base.rb:202:in `__raise_transport_error'
from /Users/apple/.rvm/gems/ruby-2.3.1/gems/elasticsearch-transport-6.0.0/lib/elasticsearch/transport/transport/base.rb:319:in `perform_request'
from /Users/apple/.rvm/gems/ruby-2.3.1/gems/elasticsearch-transport-6.0.0/lib/elasticsearch/transport/transport/http/faraday.rb:20:in `perform_request'
from /Users/apple/.rvm/gems/ruby-2.3.1/gems/elasticsearch-transport-6.0.0/lib/elasticsearch/transport/client.rb:131:in `perform_request'
from /Users/apple/.rvm/gems/ruby-2.3.1/gems/elasticsearch-api-6.0.0/lib/elasticsearch/api/namespace/common.rb:21:in `perform_request'
from /Users/apple/.rvm/gems/ruby-2.3.1/gems/elasticsearch-api-6.0.0/lib/elasticsearch/api/actions/indices/update_aliases.rb:43:in `update_aliases'
from /Users/apple/.rvm/gems/ruby-2.3.1/gems/searchkick-2.4.0/lib/searchkick/index.rb:70:in `promote'
from /Users/apple/.rvm/gems/ruby-2.3.1/gems/searchkick-2.4.0/lib/searchkick/index.rb:244:in `reindex_scope'
from /Users/apple/.rvm/gems/ruby-2.3.1/gems/searchkick-2.4.0/lib/searchkick/model.rb:72:in `searchkick_reindex'
from (irb):1
from /Users/apple/.rvm/gems/ruby-2.3.1/gems/railties-5.0.6/lib/rails/commands/console.rb:65:in `start'
from /Users/apple/.rvm/gems/ruby-2.3.1/gems/railties-5.0.6/lib/rails/commands/console_helper.rb:9:in `start'
from /Users/apple/.rvm/gems/ruby-2.3.1/gems/railties-5.0.6/lib/rails/commands/commands_tasks.rb:78:in `console'
from /Users/apple/.rvm/gems/ruby-2.3.1/gems/railties-5.0.6/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /Users/apple/.rvm/gems/ruby-2.3.1/gems/railties-5.0.6/lib/rails/commands.rb:18:in `<top (required)>'
from /Users/apple/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.6/lib/active_support/dependencies.rb:293:in `require'
from /Users/apple/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.6/lib/active_support/dependencies.rb:293:in `block in require'
from /Users/apple/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.6/lib/active_support/dependencies.rb:259:in `load_dependency'
from /Users/apple/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.6/lib/active_support/dependencies.rb:293:in `require'
from /Users/apple/rails/job-listing1129/bin/rails:9:in `<top (required)>'
from /Users/apple/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.6/lib/active_support/dependencies.rb:287:in `load'
from /Users/apple/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.6/lib/active_support/dependencies.rb:287:in `block in load'
from /Users/apple/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.6/lib/active_support/dependencies.rb:259:in `load_dependency'
from /Users/apple/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.6/lib/active_support/dependencies.rb:287:in `load'
from /Users/apple/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/apple/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
2.3.1 :002 >
I try to find solution in Google and stackoverflow, but did not find it.
I am very new to be a coder. I use ruby on rails.
I hope I didn't bring trouble to you.
Try running Job.search_index.clean_indices in the console first and see if that helps.
If you still get that error, you could also try adding the following to your searchkick config in the Job model and reindexing (although it shouldn't really be necessary):
searchkick settings: {blocks: {read_only: false}}
If you are still getting the error, then the final thing you could try would be to delete the existing index first by running Job.search_index.delete and then reindexing to create a new index.
Thanks @mikelkew.
I tried to test all your solutions several times, the last one can works always.
Thanks @mikelkew 💯
@jiujiubad @mikelkew can confirm # 3 worked great for me, thanks so much for this! 🔥
Most helpful comment
Try running
Job.search_index.clean_indicesin the console first and see if that helps.If you still get that error, you could also try adding the following to your searchkick config in the Job model and reindexing (although it shouldn't really be necessary):
searchkick settings: {blocks: {read_only: false}}If you are still getting the error, then the final thing you could try would be to delete the existing index first by running
Job.search_index.deleteand then reindexing to create a new index.