我是JEST技术的新手。我正在通过https://github.com/searchbox-io/Jest/tree/master/jest#authentication
链接进行练习。我能够创建索引并向其中添加文档,但是我想传递多个节点。
这是我的代码
JestClientFactory factory = new JestClientFactory();
factory.setHttpClientConfig(new HttpClientConfig
.Builder("http://192.167.1.2:9200")
.defaultCredentials("user", "password")
.multiThreaded(false)
//Per default this implementation will create no more than 2 concurrent connections per given route
.defaultMaxTotalConnectionPerRoute(2) // and no more 20 connections in total
.maxTotalConnection(5)
.build());
JestClient client = factory.getObject();
我有3个节点集群,所以我想在代码中传递3个节点。任何帮助将不胜感激。
谢谢
最佳答案
实际上,正如link you gave所写,您可以将一个列表传递给Builder,请参阅:
JestClientFactory factory = new JestClientFactory();
factory.setHttpClientConfig(
new HttpClientConfig.Builder(Arrays.asList("http://192.168.0.88:9200", "http://192.168.0.172:9200"))
.credentialsProvider(customCredentialsProvider)
.build()
);
实际上,更精确地说,Builder接受
Collection<String>
,请参见:https://github.com/searchbox-io/Jest/blob/master/jest/src/main/java/io/searchbox/client/config/HttpClientConfig.java#L127
关于elasticsearch - 如何在 Jest 中传递多个节点地址(Elasticsearch),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45114596/