gpt4 book ai didi

elasticsearch - 在弹性集群模式下创建Java RestHighLevelClient

转载 作者:行者123 更新时间:2023-12-02 22:35:36 28 4
gpt4 key购买 nike

如果elasticsearch在单一模式下运行,我可以使用以下代码轻松建立RestHighLevel连接:

RestHighLevelClient client = new RestHighLevelClient(
RestClient.builder(
new HttpHost("localhost", 9200, "http"),
new HttpHost("localhost", 9201, "http")));

但是,如果我的 flex 集群有3台计算机,例如“host1”,“host2”,“host3”,如何在集群模式下创建其余的高级客户端?

谢谢

最佳答案

RestHighLevelClient client = new RestHighLevelClient(
RestClient.builder(
new HttpHost("host1", 9200, "http"),
new HttpHost("host2", 9200, "http"),
new HttpHost("host2", 9200, "http")
)
);

作为 doc it looks like you were referencing states,RestClient.builder接受要连接的HttpHosts数组。客户端(实际上是ES低级REST客户端)将向这些主机轮询请求。另请参见 Javadoc

关于elasticsearch - 在弹性集群模式下创建Java RestHighLevelClient,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54975655/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com