Elasticsearch - 分配分片
我最近发现了 Elasticsearch,我决定玩一玩。不幸的是我在添加索引时遇到了麻烦。
用于添加索引的代码如下,每次尝试添加新索引时都会运行:
public void index ( String index, String type, String id, String json ){
Node node = null;
try{
node = nodeBuilder().node();
Client client = node.client();
IndexResponse response = client.prepareIndex( index, type, id )
.setSource( json )
.execute()
.actionGet();
}
catch ( Exception e ){
Logger.error( e, " Error indexing JSON file: " + json );
}
finally {
if( node != null)
node.close();
}
}
似乎没有添加索引,并且我的集群健康状况当前为红色(因为其中一个分片为红色),但我没有想法如何解决这个问题。我收到确认信息,表明我的索引每次都会被添加,但在搜索时或在 es-admin 中它们不会显示。
非常感谢所有帮助或想法。
I have recently discovered Elasticsearch and I decided to have a play. Unfortunately I am having trouble with adding indexes.
The code used to add an index is as follows and runs every time a new index is attempted to be added:
public void index ( String index, String type, String id, String json ){
Node node = null;
try{
node = nodeBuilder().node();
Client client = node.client();
IndexResponse response = client.prepareIndex( index, type, id )
.setSource( json )
.execute()
.actionGet();
}
catch ( Exception e ){
Logger.error( e, " Error indexing JSON file: " + json );
}
finally {
if( node != null)
node.close();
}
}
No indexes appear to be added and my Cluster helath is currently red (as one of the shards is red), but I have no idea how to resolve this. I am receiveing confirmation that my index is being added each time but they do not show up when searched or in es-admin.
All help or ideas are greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
启动节点时,要考虑的常见设置之一是它是否应该保存数据。换句话说,是否应该为其分配索引和分片。很多时候,我们希望客户端只是客户端,而不向他们分配分片 [1]。
如果您想将客户端设置为非数据客户端(无分片),请尝试将其替换为:
[
1] http://www.elasticsearch.org/guide/reference/java-api/client.html
When starting a Node, one of the common settings to consider is if it should hold data or not. In other words, should indices and shards be allocated to it. Many times we would like to have the clients just be clients, without shards being allocated to them [1].
If you want to set up your client as being a non-data client (no shards) try setting it up like so by replacing this:
with this:
[1] http://www.elasticsearch.org/guide/reference/java-api/client.html