Ruby on Rails - searchkick gem:cluster_block_exception - FORBIDDEN / 12 / index只读/允许删除(api) - 状态":403

时间:2018-03-08 10:49:08

标签: ruby-on-rails ubuntu elasticsearch searchkick

我尝试使用elasticsearchsearchkick gem添加到我的Ruby on Rails网站。我目前使用的操作系统是Ubuntu 16.04 TLS。

我安装了elasticsearch 6.2.2,到目前为止,默认配置没有改变。

当我运行curl -X GET 'http://localhost:9200'时,我得到:

{
    "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"
}

我想,这是想要的输出。

然后我将gem 'searchkick', '~> 3.0'添加到我的Gemfile中,运行bundle install并将searchkick添加到我的模型中。

但是,在终端中运行Activity.reindex会导致:

Activity.reindex: command not found

正在运行rake searchkick:reindex CLASS=Activity导致了一个愚蠢的错误:

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

我尝试了curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}'

但是再次重新运行rake searchkick:reindex CLASS=Activity会导致以下结果:

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}

我还尝试将searchkick settings: {blocks: {read_only: false}}添加到活动模型,但在我再次运行rake searchkick:reindex CLASS=Activity时遇到了同样的错误。

我该如何解决这个问题。

2 个答案:

答案 0 :(得分:5)

我通过在控制台中运行Activity.search_index.delete来修复它,然后重新Activity.reindex

答案 1 :(得分:1)

当我运行rspec测试并且第一个dB插入设置测试数据库env失败时,以下内容为我工作,并出现此弹性搜索错误。修复从here中提取的关键观察结果:

  

默认情况下,当您的可用磁盘空间少于5%时,在Mac OS上随家酿安装的Elasticsearch进入只读模式

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}'