首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >试图关闭elasticsearch群集时发生IndexPrimaryShardNotAllocatedException错误

试图关闭elasticsearch群集时发生IndexPrimaryShardNotAllocatedException错误
EN

Stack Overflow用户
提问于 2014-01-22 20:52:40
回答 1查看 1.4K关注 0票数 3

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

代码语言:javascript
复制
  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'

哪里

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

当我执行这段代码时,当我试图执行'close‘方法时,会出现一个错误(上面第3行)

代码语言:javascript
复制
Elasticsearch::Transport::Transport::Errors::Conflict:
   [409] {"error":"IndexPrimaryShardNotAllocatedException[[test_1] primary not allocated post api]","status":409}

我尝试过添加刷新方法(上面的第2行),它有时起作用,有时不起作用,我有一种感觉:“有时工作”意味着我做错了什么。谢谢你的帮助!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-23 01:51:52

因此,我无意中发现了使用ruby的集群健康选项,现在它似乎起作用了。

我就是这样解决的:

代码语言:javascript
复制
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

那么我上面的代码如下所示:

代码语言:javascript
复制
  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'

希望这能帮到别人!

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21293744

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档