SpringBoot整合Elasticsearch BBoss

依赖增加:

<dependency>
    <groupId>com.bbossgroups.plugins</groupId>
    <artifactId>bboss-elasticsearch-rest-jdbc</artifactId>
    <version>6.2.8</version>
</dependency>
<dependency>
    <groupId>com.bbossgroups.plugins</groupId>
    <artifactId>bboss-elasticsearch-spring-boot-starter</artifactId>
    <version>6.2.8</version>
</dependency>

yml配置

spring:
  elasticsearch:
    bboss:
      #elasticUser: username
      #elasticPassword: password
      elasticsearch:
        rest:
          hostNames: localhost:9200
          #hostNames: ip1:9200,ip2:9200,ip3:9200  ##集群地址配置
          #https配置,添加https://协议头
          #hostNames: https://ip1:9200,https://ip2:9200,https://ip3:9200
        dateFormat: yyyy-MM-dd ##日期格式
        timeZone: Asia/Shanghai  ##时区
        #在控制台输出脚本调试开关showTemplate,false关闭,true打开      
        showTemplate: true
        discoverHost: false
      #dsl配置文件热加载扫描时间间隔,毫秒为单位,默认5秒扫描一次,<= 0时关闭扫描机制
      dslfile:
        refreshInterval: -1
      ##es client http连接池配置
      http:
         #建立连接超时时间,单位:毫秒
         timeoutConnection: 5000
         #socket通讯超时时间,如果在通讯过程中出现sockertimeout异常,可以适当调整timeoutSocket参数值,单位:毫秒
         timeoutSocket: 5000
         #申请连接超时时间,设置为0不超时,单位:毫秒
         connectionRequestTimeout: 5000
         ##连接失败重试次数,默认-1,小于等于0时不重试
         retryTime: 1
         maxLineLength: -1
         maxHeaderCount: 200
         ## 总共允许的最大连接数:节点数n x defaultMaxPerRoute
         maxTotal: 400
         ## 每个地址允许的最大连接数
         defaultMaxPerRoute: 200
         soReuseAddress: false
         soKeepAlive: false
         timeToLive: 3600000
         keepAlive: 3600000
         keystore:
         keyPassword:
         # ssl 主机名称校验,是否采用default配置,
         # 如果指定为default,就采用DefaultHostnameVerifier,否则采用 SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER
         hostnameVerifier:

 使用Bboss

@Autowired
private BBossESStarter bbossESStarter;

//加载配置文件,创建es客户端工具包,在默认es数据源操作
ClientInterface clientUtil = bbossESStarter.getConfigRestClient(mappath);
或
ClientInterface clientUtil = bbossESStarter.getRestClient(); 

ESDatas<Demo> esDatas =clientUtil.searchList("demo/_search",//demo为索引表,_search为检索操作action
                queryAll,//queryAll变量对应的dsl语句
                Demo.class);
//获取结果对象列表
List<Demo> demos = esDatas.getDatas();

配置查询的dsl

resource下创建esmapper/deomo.xml,配置脚本

<properties>
   <property name="queryAll">
        <![CDATA[
            {
              "query": {
                "match_all": {}
              }
            }
        ]]>
   </property>

</properties>

简单查询完成。

文档链接ElasticsearchBboss

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值