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

bboss-elasticsearch--使用/教程/实例

邢修明
2023-12-01

原文网址:bboss-elasticsearch--使用/教程/实例_IT利刃出鞘的博客-CSDN博客

简介

说明

        本文用实例介绍bboss-elasticsearch的用法。

官网

github 官网demo

配置

打印dsl语句

步骤1 选择日志实现类

springboot与bboss都引入了slf4j的实现,需要将其中一个排除掉,因为springboot的slf4j是必须的,所以,排除掉bboss的。
log级别需要至少为info级别,因为springboot默认的控制台输出级别即为info,所以无需其他配置。

<dependency>
    <groupId>com.bbossgroups.plugins</groupId>
    <artifactId>bboss-elasticsearch-spring-boot-starter</artifactId>
    <version>6.2.5</version>
    <exclusions>
        <exclusion>
            <artifactId>slf4j-log4j12</artifactId>
            <groupId>org.slf4j</groupId>
        </exclusion>
    </exclusions>
</dependency>

步骤2 打开调试开关

# 线上环境要关闭
spring.elasticsearch.bboss.elasticsearch.showTemplate = true

步骤3 使用BBossESStarter获取ClientInterface

必须使用下边这个,若使用右边这个,则不能输出调试信息:ClientInterface clientInterface = ElasticSearchHelper.getRestClientUtil();

@Autowired
private BBossESStarter bBossESStarter;
private ClientInterface clientUtil;

@PostConstruct
public void initUtil() {
    clientUtil = bBossESStarter.getConfigRestClient(mapperPath);
}

实例

源码:shapeless/demo_ElasticSearch - Gitee

依赖及配置

依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo_bboss</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo_bboss</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.bbossgroups.plugins</groupId>
            <artifactId>bboss-elasticsearch-rest-jdbc</artifactId>
            <version>6.2.5</version>
        </dependency>
        <dependency>
            <groupId>com.bbossgroups.plugins</groupId>
            <artifactId>bboss-elasticsearch-spring-boot-starter</artifactId>
            <version>6.2.5</version>
            <exclusions>
                <exclusion>
                    <artifactId>slf4j-log4j12</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.12</version>
            <scope>provided</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

配置

spring:
  elasticsearch:
    bboss:
      #      elasticUser: elastic
      #      elasticPassword: changeme
      elasticsearch:
        rest:
          hostNames: 127.0.0.1:9200
          ##hostNames: 192.168.8.25:9200,192.168.8.26:9200,192.168.8.27:9200  ##集群地址配置
        dateFormat: yyyy.MM.dd
        timeZone: Asia/Shanghai
        showTemplate: true
        discoverHost: false
      dslfile:
        refreshInterval: -1
      http:
        timeoutConnection: 5000
        timeoutSocket: 5000
        connectionRequestTimeout: 5000
        retryTime: 1
        maxLineLength: -1
        maxHeaderCount: 200
        maxTotal: 400
        defaultMaxPerRoute: 200
        soReuseAddress: false
        soKeepAlive: false
        timeToLive: 3600000
        keepAlive: 3600000
        keystore:
        keyPassword:
        hostnameVerifier:

增删改查(基本)

增删改查(Mapper)

查询(基本)

查询(分页)

查询(Mapper)

查询(SQL)

查询(URL)

其他网址

基于springboot+bboss整合的elasticsearch(好用的一匹)_toBeMN的博客-CSDN博客_bboss
springboot集成bboss操作elasticsearch索引,类型,文档(单集群)_不经意的博客-CSDN博客

 类似资料: