如何初始化Elasticsearch REST客户端

时间:2018-06-06 01:28:31

标签: rest elasticsearch

假设我有一个包含符合主节点的节点,数据节点和协调节点的集群。当我初始化REST客户端时,我应该包括上述哪种节点类型?所有节点,只有数据节点,只有协调节点,或它们的某种组合?

例如:

RestClient restClient = RestClient.builder(
new HttpHost("master-eligible-node-1", 9200, "http"),
new HttpHost("master-eligible-node-2", 9200, "http"),
new HttpHost("master-eligible-node-3", 9200, "http")).build();

,或者

RestClient restClient = RestClient.builder(
new HttpHost("master-eligible-node-1", 9200, "http"),
new HttpHost("master-eligible-node-2", 9200, "http"),
...
new HttpHost("master-eligible-node-n", 9200, "http"),
new HttpHost("data-node-1", 9200, "http"),
new HttpHost("data-node-2", 9200, "http"),
...
new HttpHost("data-node-n", 9200, "http"),
new HttpHost("coord-node-1", 9200, "http"),
new HttpHost("coord-node-2", 9200, "http"),
...
new HttpHost("coord-node-n", 9200, "http")).build();

作为第二部分,是否可以仅将REST客户端初始化为协调节点,或仅初始化为数据节点?我想如果我想隔离查询操作和索引操作,我可能想要这样做。

谢谢!

1 个答案:

答案 0 :(得分:0)

经验法则是:

  1. 从不直接连接到符合条件的节点
  2. 如果您有专用的协调节点,请使用它们
  3. 否则连接到您的数据节点,这些节点本身也充当协调节点