add:集成es搜索模块

This commit is contained in:
2510220824
2021-06-22 17:14:39 +08:00
parent 90b6714345
commit 51d3edebfd
36 changed files with 8166 additions and 0 deletions
@@ -0,0 +1,57 @@
package com.adc.da.search.config;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.net.InetAddress;
import java.net.UnknownHostException;
/**
* gaoyan
* 2018-08-23
* elasticsearch配置config
*/
@Configuration
public class ElasticsearchConfig {
private static final Logger logger = LoggerFactory.getLogger(ElasticsearchConfig.class);
@Autowired
private ElasticsearchProperties elasticsearchProperties;
@Bean
public TransportClient client() throws UnknownHostException {
TransportClient client = null;
try {
Settings settings = Settings.builder()
.put("client.transport.sniff", true)//增加嗅探机制,找到ES集群
.put("thread_pool.search.size", elasticsearchProperties.getPoolSize())//增加线程池个数,暂时设为5
.put("cluster.name",elasticsearchProperties.getClustername())
.build();
client = new PreBuiltTransportClient(settings)
.addTransportAddress(new TransportAddress(InetAddress.getByName(elasticsearchProperties.getIp()),elasticsearchProperties.getPort()));
} catch (java.net.UnknownHostException e) {
logger.error(e.getMessage(),e);
}
return client;
}
/*@After
public void tearDown() throws Exception {
if (client != null) {
client.close();
}
}*/
}
@@ -0,0 +1,45 @@
package com.adc.da.search.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties(prefix = "elasticsearch")
public class ElasticsearchProperties {
private String clustername;
private String ip;
private Integer port;
private Integer poolSize;
public String getClustername() {
return clustername;
}
public void setClustername(String clustername) {
this.clustername = clustername;
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public Integer getPort() {
return port;
}
public void setPort(Integer port) {
this.port = port;
}
public Integer getPoolSize() {
return poolSize;
}
public void setPoolSize(Integer poolSize) {
this.poolSize = poolSize;
}
}