开发者

Elasticsearch - Assigning Shards

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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜