springboot整合elasticsearch

本文详细介绍了如何在SpringBoot应用中集成并配置Elasticsearch,包括安装步骤、依赖引入、配置文件设置、索引创建及数据导入等关键步骤,帮助开发者快速掌握二者结合的实践技巧。
摘要由CSDN通过智能技术生成
#application.properties配置

##单集群配置,如果需要做多集群配置,参照application.properties.multicluster文件
elasticsearch.serverNames = default

##default集群配配置
# x-pack或者searchguard安全认证和口令配置
elasticUser=admin
elasticPassword=admin

#集群地址配置
#elasticsearch.rest.hostNames=10.180.211.27:9280,10.180.211.27:9281,10.180.211.27:9282
#Proxy Node
#elasticsearch.rest.hostNames=192.168.137.1:9206,192.168.137.1:9207
#elasticsearch.rest.hostNames=https://10.13.11.5:9200
elasticsearch.rest.hostNames=127.0.0.1:9200
#如果开启了https协议,则需要在elasticsearch地址中添加https://协议头
#elasticsearch.rest.hostNames=https://10.180.211.27:9280,https://10.180.211.27:9281,https://10.180.211.27:9282
elasticsearch.dateFormat=yyyy.MM.dd
elasticsearch.timeZone=Asia/Shanghai
#在控制台输出脚本调试开关showTemplate,false关闭,true打开,同时log4j至少是info级别
elasticsearch.showTemplate=false
#集群节点自动发现开关
elasticsearch.discoverHost=true
elasticsearch.useHttps=false

#设置slice scroll查询对应的线程数和等待队列数
elasticsearch.sliceScrollThreadCount=100
elasticsearch.sliceScrollThreadQueue=100
elasticsearch.sliceScrollBlockedWaitTimeout=0

#设置scroll查询对应的线程数和等待队列数
elasticsearch.scrollThreadCount=50
elasticsearch.scrollThreadQueue=50
elasticsearch.scrollBlockedWaitTimeout=0
elasticsearch.includeTypeName = false
#elasticsearch.slowDslThreshold = 1000
#elasticsearch.slowDslCallback=org.bboss.elasticsearchtest.crud.TestSlowDslCallback
##default连接池配置
http.timeoutConnection = 10000
http.timeoutSocket = 50000
http.connectionRequestTimeout=10000
http.retryTime = 3
http.retryInterval = 3000
http.maxLineLength = -1
http.maxHeaderCount = 200
http.maxTotal = 400
http.defaultMaxPerRoute = 200
http.soReuseAddress = false
http.soKeepAlive = false
http.timeToLive = 3600000
http.keepAlive = 3600000
# Using the keystore- and truststore file
## http.keystore = D:/workspace/bbossesdemo/eshelloword-booter/src/main/resources/sgadmin-keystore.jks
## http.keyPassword = 7240a0366eb6a764103e
## http.truststore = D:/workspace/bbossesdemo/eshelloword-booter/src/main/resources/truststore.jks
## http.trustPassword = 6aa4bd79096852203a5b

# Using PEM certificates
## http.pemCert = D:/workspace/bbossesdemo/eshelloword-booter/src/main/resources/sgadmin.crtfull.pem
## http.pemtrustedCA = D:/workspace/bbossesdemo/eshelloword-booter/src/main/resources/chain-ca.pem
## http.pemKey = D:/workspace/bbossesdemo/eshelloword-booter/src/main/resources/sgadmin.key.pem
## http.pemkeyPassword = 7240a0366eb6a764103e

# ssl 主机名称校验,是否采用default配置,
# 如果指定为default,就采用DefaultHostnameVerifier,否则采用 SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER
http.hostnameVerifier =
# 驱逐http连接池中过期的http连接
http.evictExpiredConnections=true
#每隔多少毫秒校验空闲connection,自动释放无效链接
# -1 或者0不检查
http.validateAfterInactivity=3000
# 每次获取connection时校验连接,true,校验,false不校验,有性能开销

# 默认值false
http.staleConnectionCheckEnabled=false
#* 自定义重试控制接口,必须实现接口方法
#* public interface CustomHttpRequestRetryHandler  {
   
#* 	public boolean retryRequest(IOException exception, int executionCount, HttpContext context,ClientConfiguration configuration);
#* }
#* 方法返回true,进行重试,false不重试
# http.customHttpRequestRetryHandler=org.frameworkset.spi.remote.http.DefaultHttpRequestRetryHandler
http.customHttpRequestRetryHandler=org.frameworkset.spi.remote.http.ConnectionResetHttpRequestRetryHandler


# dsl配置文件热加载扫描时间间隔,毫秒为单位,默认5秒扫描一次,<= 0时关闭扫描机制
dslfile.refreshInterval = 5000
# 指定存放dsl配置文件的地址
#dslfile.dslMappingDir=D:/workspace/bbossesdemo/eshelloword-booter/src/main/resources/

# 演示数据库数据导入elasticsearch源配置
db.name = test
db.user = root
db.password = 123456
db.driver = com.mysql.jdbc.Driver
db.url = jdbc:mysql://localhost:3306/test?useCursorFetch=true
db.usePool = true
db.validateSQL = select 1
db.jdbcFetchSize = 10000
db.showsql = true

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

/**
 * 获取application.properties中配置值
 * @author hy
 *
 */
@Configuration
public class ElasticsearchConfig {
   
    @Value("${db.name}")
    private String dbName;
    @Value("${db.user}")
    private String dbUser;
    @Value("${db.password}")
    private String dbPassword;
    @Value("${db.driver}")
    private String dbDriver;
    @Value("${db.url}")
    private String dbUrl;
    @Value("${db.usePool}")
    private Boolean dbUsePool;
    @Value("${db.validateSQL}")
    private String dbValidateSQL;
    @Value("${db.jdbcFetchSize}")
    private Long dbJdbcFetchSize;
    
	public String getDbName() {
   
		return dbName;
	}
	public void setDbName(String dbName) {
   
		this.dbName = dbName;
	}
	public String getDbUser() {
   
		return dbUser;
	}
	public void setDbUser(String dbUser) {
   
		this.dbUser = dbUser;
	}
	public String getDbPassword() {
   
		return dbPassword;
	}
	public void setDbPassword(String dbPassword) {
   
		this.dbPassword = dbPassword;
	}
	public String getDbDriver() {
   
		return dbDriver;
	}
	public void setDbDriver(String dbDriver) {
   
		this.dbDriver = dbDriver;
	}
	public String getDbUrl() {
   
		return dbUrl;
	}
	public void setDbUrl(String dbUrl) {
   
		this.dbUrl = dbUrl;
	}
	public Boolean getDbUsePool
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值