Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails - searchkick gem : cluster_block_exception - FORBIDDEN/12/index read-only / allow delete (api) - status":403

I'm trying to add elasticsearch to my Ruby on Rails website using searchkick gem. The OS I'm currently using is Ubuntu 16.04 TLS.

I installed elasticsearch 6.2.2 and, so far, the default configurations unchanged.

When I run curl -X GET 'http://localhost:9200' I get :

{
    "name" : "viTKcuN",
    "cluster_name" : "elasticsearch",
    "cluster_uuid" : "aHCpbpvoQd2sieJRWtqI7g",
    "version" : {
        "number" : "6.2.2",
        "build_hash" : "10b1edd",
        "build_date" : "2018-02-16T19:01:30.685723Z",
        "build_snapshot" : false,
        "lucene_version" : "7.2.1",
        "minimum_wire_compatibility_version" : "5.6.0",
        "minimum_index_compatibility_version" : "5.0.0"
    },
    "tagline" : "You Know, for Search"
}

Which, I guess, the desired output.

I then added gem 'searchkick', '~> 3.0' to my Gemfile, ran bundle install and added searchkick to my models.

However, running Activity.reindex in terminal results in:

Activity.reindex: command not found

Running rake searchkick:reindex CLASS=Activity resulted in the foolowing error:

rails searchkick earchkick::ImportError: {"type"=>"cluster_block_exception", "reason"=>"blocked by: [FORBIDDEN/12/index read-only / allow delete (api)];"} on item with id '1'

I tried running curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}'

But then rerunning rake searchkick:reindex CLASS=Activity again results in the following:

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}

I also tried adding searchkick settings: {blocks: {read_only: false}} to the Activity model but had the same error when I ran rake searchkick:reindex CLASS=Activity again.

How can I solve this problem.

like image 788
TamerB Avatar asked Mar 08 '18 10:03

TamerB


2 Answers

I fixed it by running Activity.search_index.delete in console and then reran Activity.reindex

like image 155
TamerB Avatar answered Oct 19 '22 04:10

TamerB


The following worked for me when I got this running rspec tests and the first dB insert setting up the test db env failed with this elastic search error. Fix extracted from here, the key observation:

By default, Elasticsearch installed with homebrew on Mac OS goes into read-only mode when you have less than 5% of free disk space.

curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_cluster/settings -d '{ "transient": { "cluster.routing.allocation.disk.threshold_enabled": false } }'
curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}'
like image 45
FlimFlam Vir Avatar answered Oct 19 '22 03:10

FlimFlam Vir