【问题标题】:Ruby on Rails - searchkick gem : cluster_block_exception - FORBIDDEN/12/index read-only / allow delete (api) - status":403Ruby on Rails - searchkick gem:cluster_block_exception - FORBIDDEN/12/index 只读/允许删除(api) - 状态“:403
【发布时间】:2018-08-16 16:44:19
【问题描述】:

我正在尝试使用searchkick gemelasticsearch 添加到我的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}} 添加到 Activity 模型,但再次运行 rake searchkick:reindex CLASS=Activity 时出现同样的错误。

我该如何解决这个问题。

【问题讨论】:

    标签: ruby-on-rails ubuntu elasticsearch searchkick


    【解决方案1】:

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

    【讨论】:

    • 这当然有效,但它相当于在您的操作系统出现问题时格式化和重新安装 Windows。 @FlimFlam Vir 有正确的手术方法。
    【解决方案2】:

    当我得到这个正在运行的 rspec 测试并且设置测试 db env 的第一个 dB 插入失败并出现此弹性搜索错误时,以下内容对我有用。修复提取自here,关键观察:

    默认情况下,在 Mac OS 上随 homebrew 一起安装的 Elasticsearch 会在您的可用磁盘空间不足 5% 时进入只读模式。

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

    【讨论】:

    • 对我有用的正确命令是curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": false}'
    猜你喜欢
    • 2019-05-30
    • 2020-01-10
    • 2021-04-05
    • 2019-10-16
    • 1970-01-01
    • 2018-06-10
    • 2018-04-11
    • 1970-01-01
    • 2013-11-02
    相关资源
    最近更新 更多