Elasticsearch - 分配分片

发布于 2024-11-01 05:40:13 字数 761 浏览 7 评论 0原文

我最近发现了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇纵 2024-11-08 05:40:13

启动节点时,要考虑的常见设置之一是它是否应该保存数据。换句话说,是否应该为其分配索引和分片。很多时候,我们希望客户端只是客户端,而不向他们分配分片 [1]。

如果您想将客户端设置为非数据客户端(无分片),请尝试将其替换为:

node = nodeBuilder().node();

[

node = nodeBuilder().client(true).node();

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:

node = nodeBuilder().node();

with this:

node = nodeBuilder().client(true).node();

[1] http://www.elasticsearch.org/guide/reference/java-api/client.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文