gpt4 book ai didi

ruby - 尝试关闭 Elasticsearch 集群时出现 IndexPrimaryShardNotAllocatedException 错误

转载 作者:数据小太阳 更新时间:2023-10-29 07:50:03 26 4
gpt4 key购买 nike

在我的机器上使用 https://gist.github.com/wingdspur/2026107 安装 elasticsearch 之后它在 http://localhost:9200 启动了一个 elasticsearch 集群,我正在尝试创建一个带有设置的索引并使用了这段代码:

  search_indices.create index: 'test'
search_indices.refresh index: 'test'
search_indices.close index: 'test'
search_indices.put_settings(index: 'test', **my_index_settings)
search_indices.put_mapping(index: 'test', **my_mapping_settings)
search_indices.open index: 'test'

在哪里

search_indices = Elasticsearch::Client.new({host: 'http://localhost:9200'}).indices
# this module comes from the elasticsearch-ruby gem

当我执行这段代码时,当我尝试执行“close”方法(上面的第 3 行)时出现错误

Elasticsearch::Transport::Transport::Errors::Conflict:
[409] {"error":"IndexPrimaryShardNotAllocatedException[[test_1] primary not allocated post api]","status":409}

我已经尝试添加刷新方法(上面的第 2 行),它有时有效,有时无效,我感觉“有时有效”意味着我做错了什么。感谢您的帮助!

最佳答案

所以我偶然发现了带有 ruby​​ API 的集群健康选项,现在它似乎可以工作了。

我是这样解决的:

def search_client
# I should memoize this so I don't have to keep creating new indices
@search_client ||= Elasticsearch::Client.new({host: 'http://localhost:9200'})
end

def search_indices
search_client.indices
end

然后我上面的代码看起来像:

  search_indices.create index: 'test'
search_client.cluster.health wait_for_status: 'green'
search_indices.close index: 'test'
search_indices.put_settings(index: 'test', **my_index_settings)
search_indices.put_mapping(index: 'test', **my_mapping_settings)
search_indices.open index: 'test'

希望这对某人有帮助!

关于ruby - 尝试关闭 Elasticsearch 集群时出现 IndexPrimaryShardNotAllocatedException 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21293744/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com