我有一个 Java API 可以将文档插入三个弹性索引并且它正在工作。我想在 API 中更改一个索引的主机。通常,EsConfig 文件和 ElasticSearchTemplate 代码是 ;
public class EsConfig {
@Value("${elasticsearch.host}")
private String EsHost;
@Value("${elasticsearch.port}")
private int EsPort;
@Value("${elasticsearch.clustername}")
private String EsClusterName;
@Bean
public Client client() throws Exception {
Settings settings = Settings.builder()
.put("cluster.name", EsClusterName)
//.put("index.max_result_window", 4000000)
.build();
TransportClient client = new PreBuiltTransportClient(settings)
.addTransportAddress(new
TransportAddress(InetAddress.getByName(EsHost), EsPort));
return client;
}
@Bean
public ElasticsearchTemplate elasticsearchTemplate() throws Exception {
ElasticsearchTemplate elasticsearchTemplate = new ElasticsearchTemplate(client());
return elasticsearchTemplate;
}
}
我想将此结构配置为一起使用两个主机。这种结构有可能还是我应该完全改变和删除单例bean结构?