我们在application.properties文件中提供的弹性搜索集群名称。如果Elasticsearch中没有该集群名称,它将创建一个新集群名称吗?
@Configuration
public class ElasticSearchConfiguration
{
@Value("${spring.data.elasticsearch.cluster-name}")
private String clusterName;
@Value("${spring.data.elasticsearch.cluster-nodes}")
private String clusterNodes;
@Bean
public ElasticsearchTemplate elasticsearchTemplate() throws UnknownHostException
{
String server = clusterNodes.split(":")[0];
Integer port = Integer.parseInt(clusterNodes.split(":")[1]);
Settings settings = Settings.settingsBuilder()
.put("cluster.name", clusterName).build();
client = TransportClient.builder().settings(settings).build()
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(server), port));
return new ElasticsearchTemplate(client);
}
}