在使用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行),它有时起作用,有时不起作用,我有一种感觉:“有时工作”意味着我做错了什么。谢谢你的帮助!
发布于 2014-01-23 01:51:52
因此,我无意中发现了使用ruby的集群健康选项,现在它似乎起作用了。
我就是这样解决的:
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'希望这能帮到别人!
https://stackoverflow.com/questions/21293744
复制相似问题