|
@ -17,6 +17,7 @@ import org.springframework.context.annotation.Configuration;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
import java.net.InetAddress;
|
|
|
import java.net.UnknownHostException;
|
|
|
import java.util.Arrays;
|
|
@ -49,6 +50,16 @@ public class ElasticFactory {
|
|
|
* 初始化链接
|
|
|
* 9200
|
|
|
*/
|
|
|
@PostConstruct
|
|
|
public void initAll() {
|
|
|
try {
|
|
|
init();
|
|
|
initTranClient();
|
|
|
} catch (UnknownHostException e) {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public synchronized void init() {
|
|
|
String[] hostArray = elasticSearchPorperties.getClusterNodesJest().split(",");
|
|
|
// Construct a new Jest client according to configuration via factory
|
|
@ -90,7 +101,7 @@ public class ElasticFactory {
|
|
|
if (transportClient == null) {
|
|
|
String[] hosts = elasticSearchPorperties.getClusterNodes().split(",");
|
|
|
Settings settings = Settings.settingsBuilder()
|
|
|
.put("client.transport.sniff", elasticSearchPorperties.getJestDiscoveryEnabled())//开启嗅探功能
|
|
|
.put("client.transport.sniff", elasticSearchPorperties.getJestDiscoveryEnabled())//开启嗅探功能
|
|
|
.put("cluster.name", StringUtils.isEmpty(elasticSearchPorperties.getClusterName()) ? "jkzl" : elasticSearchPorperties.getClusterName())//默认集群名字是jkzl
|
|
|
.build();
|
|
|
|