我是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个节点。任何帮助将不胜感激。
谢谢
答案 0 :(得分:1)
实际上,正如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()
);
实际上更精确一点,构建器接受Collection<String>
,请参阅:https://github.com/searchbox-io/Jest/blob/master/jest/src/main/java/io/searchbox/client/config/HttpClientConfig.java#L127