当前位置: 首页 > 工具软件 > bboss > 使用案例 >

项目整合bboss框架连接Elasticsearch

王高邈
2023-12-01

bbosss框架:https://www.oschina.net/p/bboss-elastic

bboss框架:https://blog.csdn.net/No_Game_No_Life_/article/details/90407228

bboss框架:https://www.oschina.net/news/110549/elasticsearch-rest-client-bboss-5-8-9-released

bboss框架集成文档

1.引入maven坐标

<dependency>

<groupId>com.bbossgroups.plugins</groupId>

<artifactId>bboss-elasticsearch-spring-boot-starter</artifactId>

<version>5.9.1</version>

</dependency>

2.集成配置

#单节点配置

spring.elasticsearch.bboss.elasticsearch.rest.hostNames=10.21.20.168:9200

#集群节点配置

spring.elasticsearch.bboss.elasticsearch.rest.hostNames=10.180.211.27:9200,10.180.211.28:9200,10.180.211.29:9200

#使用https协议

spring.elasticsearch.bboss.default.elasticsearch.rest.hostNames=https://10.180.211.27:9280,https://10.180.211.27:9281,https://10.180.211.27:9282

#兼容支持ES6版本的索引类型

spring.elasticsearch.bboss.elasticsearch.includeTypeName = true

#x-pack支持配置ES用户名

spring.elasticsearch.bboss.elasticUser=elastic

#x-pack支持配置ES密码

spring.elasticsearch.bboss.elasticPassword=changeme

#按日期动态产生的索引索引名称的日期格式

spring.elasticsearch.bboss.elasticsearch.dateFormat=yyyy.MM.dd

#时区

spring.elasticsearch.bboss.elasticsearch.timeZone=Asia/Shanghai

spring.elasticsearch.bboss.elasticsearch.ttl=2d

#在控制台输出脚本调试开关showTemplate,false关闭,true打开,同时log4j至少是info级别

spring.elasticsearch.bboss.elasticsearch.showTemplate=true

spring.elasticsearch.bboss.elasticsearch.discoverHost=false

# dsl配置文件热加载扫描时间间隔,毫秒为单位,默认5秒扫描一次,<= 0时关闭扫描机制

spring.elasticsearch.bboss.dslfile.refreshInterval = -1

##es client http连接池配置

spring.elasticsearch.bboss.http.timeoutConnection = 50000

spring.elasticsearch.bboss.http.timeoutSocket = 50000

spring.elasticsearch.bboss.http.connectionRequestTimeout=50000

spring.elasticsearch.bboss.http.retryTime = 1

spring.elasticsearch.bboss.http.maxLineLength = -1

spring.elasticsearch.bboss.http.maxHeaderCount = 200

spring.elasticsearch.bboss.http.maxTotal = 400

spring.elasticsearch.bboss.http.defaultMaxPerRoute = 200

spring.elasticsearch.bboss.http.soReuseAddress = false

spring.elasticsearch.bboss.http.soKeepAlive = false

spring.elasticsearch.bboss.http.timeToLive = 3600000

spring.elasticsearch.bboss.http.keepAlive = 3600000

spring.elasticsearch.bboss.http.keystore =

spring.elasticsearch.bboss.http.keyPassword =

# ssl 主机名称校验,是否采用default配置,

# 如果指定为default,就采用DefaultHostnameVerifier,否则采用 SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER

spring.elasticsearch.bboss.http.hostnameVerifier =

## 数据库数据源配置,使用db-es数据导入功能时需要配置

#spring.elasticsearch.bboss.db.name = test

#spring.elasticsearch.bboss.db.user = root

#spring.elasticsearch.bboss.db.password = 123456

#spring.elasticsearch.bboss.db.driver = com.mysql.jdbc.Driver

#spring.elasticsearch.bboss.db.url = jdbc:mysql://localhost:3306/bboss

#spring.elasticsearch.bboss.db.usePool = false

#spring.elasticsearch.bboss.db.validateSQL = select

 

5.使用示例

(1)直接注入类

 

 

@Autowired

private BBossESStarter bbossESStarter;

//读取配置文件

ClientInterface clientUtil = bbossESStarter.getConfigRestClient(mappath);

//创建客户端

ClientInterface clientUtil = bbossESStarter.getRestClient();

(2)定义mapper.xml

<properties>

<property name="createDemoIndice">

<![CDATA[{

"settings": {

"number_of_shards": 6,

"index.refresh_interval": "5s"

},

"mappings": {

"demo": {

"properties": {

"demoId":{

"type":"long"

},

"contentbody": {

"type": "text"

},

"agentStarttime": {

"type": "date"

},

"agentStarttimezh": {

"type": "date",

"format":"yyyy-MM-dd HH:mm:ss"

},

"applicationName": {

"type": "text",

"fields": { ##Note: define an internal keyword field for precision search

"keyword": {

"type": "keyword"

}

}

},

"name": {

"type": "text"

},

"contrastStatus":{

"type":"integer"

},

"orderId": {

"type": "text",

"fields": { ##Note: define an internal keyword field for precision search

"keyword": {

"type": "keyword"

}

}

}

}

}

}

}]]>

</property>

<property name="searchDatas">

<![CDATA[{

"query": {

"bool": {

"filter": [

{ ## Multi-terms search, find multiple application name corresponding to the document records

"terms": {

"applicationName.keyword": [#[applicationName1],#[applicationName2]]

}

},

{ ## Time range search, return the corresponding time range of records

"range": {

"agentStarttime": {

"gte": #[startTime],##Statistical start time

"lt": #[endTime] ##Statistical end time

}

}

}

]

}

},

## Up to 1000 records are returned

"size":1000

}]]>

</property>

</properties>

 类似资料: