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.
I fixed it by running Activity.search_index.delete
in console and then reran Activity.reindex
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}'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With