Spring boot整合ElasticSearch案例分享

bboss

The best elasticsearch highlevel java rest api——-bboss

Spring boot整合ElasticSearch HighLevel Rest Client案例分享,本文涉及内容

  • 集成bboss es starter
  • 单es集群整合
  • 多es集群整合

本文内容适合于:

  • spring boot 1.x,2.x
  • elasticsearch 1.x,2.x,5.x,6.x,+

1.集成bboss es starter

在spring boot项目中导入bboss es starter

maven工程

  1. <dependency>
  2. <groupId>com.bbossgroups.plugins</groupId>
  3. <artifactId>bboss-elasticsearch-spring-boot-starter</artifactId>
  4. <version>5.5.3</version>
  5. </dependency>

gradle工程

  1. compile "com.bbossgroups.plugins:bboss-elasticsearch-spring-boot-starter:5.5.3"

2.创建spring boot启动类

新建Application类:

  1. package org.bboss.elasticsearchtest.springboot;
  2. import org.frameworkset.elasticsearch.ElasticSearchHelper;
  3. import org.frameworkset.elasticsearch.client.ClientInterface;
  4. import org.slf4j.Logger;
  5. import org.slf4j.LoggerFactory;
  6. import org.springframework.boot.SpringApplication;
  7. import org.springframework.boot.autoconfigure.SpringBootApplication;
  8. import org.springframework.context.annotation.Bean;
  9. /**
  10. * @author yinbp [122054810@qq.com]
  11. *
  12. */
  13. @SpringBootApplication
  14. public class Application {
  15. private Logger logger = LoggerFactory.getLogger(Application.class);
  16. public static void main(String[] args) {
  17. SpringApplication.run(Application.class, args);
  18. }
  19. }

Application类中定义了一个main方法用来启动spring boot测试应用。

Application类将被用于启动下面两个测试用例:

  • 单es集群测试用例
  • 多es集群测试用例

3.单es集群配置和使用

3.1 配置单es集群

bboss es starter配置单集群可以采用properties文件也可以采用yml进行配置,二者任选其一。

3.1.1 application.properties

修改spring boot配置文件application.properties内容

  1. ##ES集群配置,支持x-pack和searchguard
  2. spring.elasticsearch.bboss.elasticUser=elastic
  3. spring.elasticsearch.bboss.elasticPassword=changeme
  4. spring.elasticsearch.bboss.elasticsearch.rest.hostNames=10.21.20.168:9200
  5. #spring.elasticsearch.bboss.elasticsearch.rest.hostNames=10.180.211.27:9280,10.180.211.27:9281,10.180.211.27:9282
  6. ##https配置,添加https://协议头
  7. #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
  8. spring.elasticsearch.bboss.elasticsearch.dateFormat=yyyy.MM.dd
  9. spring.elasticsearch.bboss.elasticsearch.timeZone=Asia/Shanghai
  10. spring.elasticsearch.bboss.elasticsearch.ttl=2d
  11. #在控制台输出脚本调试开关showTemplate,false关闭,true打开,同时log4j至少是info级别
  12. spring.elasticsearch.bboss.elasticsearch.showTemplate=true
  13. spring.elasticsearch.bboss.elasticsearch.discoverHost=false
  14. # dsl配置文件热加载扫描时间间隔,毫秒为单位,默认5秒扫描一次,<= 0时关闭扫描机制
  15. spring.elasticsearch.bboss.dslfile.refreshInterval = -1
  16. ##es client http连接池配置
  17. spring.elasticsearch.bboss.http.timeoutConnection = 5000
  18. spring.elasticsearch.bboss.http.timeoutSocket = 5000
  19. spring.elasticsearch.bboss.http.connectionRequestTimeout=5000
  20. spring.elasticsearch.bboss.http.retryTime = 1
  21. spring.elasticsearch.bboss.http.maxLineLength = -1
  22. spring.elasticsearch.bboss.http.maxHeaderCount = 200
  23. spring.elasticsearch.bboss.http.maxTotal = 400
  24. spring.elasticsearch.bboss.http.defaultMaxPerRoute = 200
  25. spring.elasticsearch.bboss.http.soReuseAddress = false
  26. spring.elasticsearch.bboss.http.soKeepAlive = false
  27. spring.elasticsearch.bboss.http.timeToLive = 3600000
  28. spring.elasticsearch.bboss.http.keepAlive = 3600000
  29. spring.elasticsearch.bboss.http.keystore =
  30. spring.elasticsearch.bboss.http.keyPassword =
  31. # ssl 主机名称校验,是否采用default配置,
  32. # 如果指定为default,就采用DefaultHostnameVerifier,否则采用 SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER
  33. spring.elasticsearch.bboss.http.hostnameVerifier =
  34. ## 数据库数据源配置,使用db-es数据导入功能时需要配置
  35. #spring.elasticsearch.bboss.db.name = test
  36. #spring.elasticsearch.bboss.db.user = root
  37. #spring.elasticsearch.bboss.db.password = 123456
  38. #spring.elasticsearch.bboss.db.driver = com.mysql.jdbc.Driver
  39. #spring.elasticsearch.bboss.db.url = jdbc:mysql://localhost:3306/bboss
  40. #spring.elasticsearch.bboss.db.usePool = false
  41. #spring.elasticsearch.bboss.db.validateSQL = select 1

单ES集群配置项都是以spring.elasticsearch.bboss开头。

3.1.2 application.yml

如果采用application.yml配置,内容如下

  1. spring:
  2. elasticsearch:
  3. bboss:
  4. elasticUser: elastic
  5. elasticPassword: changeme
  6. elasticsearch:
  7. rest:
  8. hostNames: 192.168.8.25:9200
  9. ##hostNames: 192.168.8.25:9200,192.168.8.26:9200,192.168.8.27:9200 ##集群地址配置
  10. dateFormat: yyyy.MM.dd
  11. timeZone: Asia/Shanghai
  12. ttl: 2d
  13. showTemplate: true
  14. discoverHost: false
  15. dslfile:
  16. refreshInterval: -1
  17. http:
  18. timeoutConnection: 5000
  19. timeoutSocket: 5000
  20. connectionRequestTimeout: 5000
  21. retryTime: 1
  22. maxLineLength: -1
  23. maxHeaderCount: 200
  24. maxTotal: 400
  25. defaultMaxPerRoute: 200
  26. soReuseAddress: false
  27. soKeepAlive: false
  28. timeToLive: 3600000
  29. keepAlive: 3600000
  30. keystore:
  31. keyPassword:
  32. hostnameVerifier:

3.2 单集群测试用例

编写es单集群测试用例BBossESStarterTestCase

  1. /*
  2. * Copyright 1999-2018 Alibaba Group Holding Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.bboss.elasticsearchtest.springboot;
  17. import org.frameworkset.elasticsearch.client.ClientInterface;
  18. import org.junit.Test;
  19. import org.junit.runner.RunWith;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.boot.test.context.SpringBootTest;
  22. import org.springframework.test.context.junit4.SpringRunner;
  23. /**
  24. * 单集群演示功能测试用例,spring boot配置项以spring.elasticsearch.bboss开头
  25. * 对应的配置文件为application.properties文件
  26. * @author yinbp [122054810@qq.com]
  27. */
  28. @RunWith(SpringRunner.class)
  29. @SpringBootTest(classes = Application.class)
  30. public class BBossESStarterTestCase {
  31. @Autowired
  32. private BBossESStarter bbossESStarter;
  33. @Autowired
  34. DocumentCRUD documentCRUD;
  35. @Test
  36. public void testBbossESStarter() throws Exception {
  37. // System.out.println(bbossESStarter);
  38. //验证环境,获取es状态
  39. // String response = serviceApiUtil.restClient().executeHttp("_cluster/state?pretty",ClientInterface.HTTP_GET);
  40. // System.out.println(response);
  41. //判断索引类型是否存在,false表示不存在,正常返回true表示存在
  42. boolean exist = bbossESStarter.getRestClient().existIndiceType("twitter","tweet");
  43. //判读索引是否存在,false表示不存在,正常返回true表示存在
  44. exist = bbossESStarter.getRestClient().existIndice("twitter");
  45. exist = bbossESStarter.getRestClient().existIndice("agentinfo");
  46. }
  47. @Test
  48. public void testCRUD() throws Exception {
  49. //删除/创建文档索引表
  50. documentCRUD.testCreateIndice();
  51. //添加/修改单个文档
  52. documentCRUD.testAddAndUpdateDocument();
  53. //批量添加文档
  54. documentCRUD.testBulkAddDocument();
  55. //检索文档
  56. documentCRUD.testSearch();
  57. //批量修改文档
  58. documentCRUD.testBulkUpdateDocument();
  59. //检索批量修改后的文档
  60. documentCRUD.testSearch();
  61. //带list复杂参数的文档检索操作
  62. documentCRUD.testSearchArray();
  63. //带from/size分页操作的文档检索操作
  64. documentCRUD.testPagineSearch();
  65. //带sourcefilter的文档检索操作
  66. documentCRUD.testSearchSourceFilter();
  67. documentCRUD.updateDemoIndice();
  68. documentCRUD.testBulkAddDocuments();
  69. }
  70. @Test
  71. public void testPerformaceCRUD() throws Exception {
  72. //删除/创建文档索引表
  73. documentCRUD.testCreateIndice();
  74. documentCRUD.testBulkAddDocuments();
  75. }
  76. }

直接通过junit运行上述测试用例即可。

其中

  1. BBossESStarter:由bboss提供,直接在代码中声明引用,并使用即可
  2. DocumentCRUD:各种增删改查操作实例,在demo工程中提供

4.多ES集群测试用例

4.1 配置多es集群

bboss es starter配置多集群可以采用properties文件也可以采用yml进行配置,二者任选其一。

4.1.1properties配置

修改spring boot配置文件application-multi-datasource.properties,内容如下:

  1. ##多集群配置样例,如果需要做多集群配置,请将参照本文内容修改application.properties文件内容
  2. spring.elasticsearch.bboss.default.name = default
  3. ##default集群配配置
  4. spring.elasticsearch.bboss.default.elasticUser=elastic
  5. spring.elasticsearch.bboss.default.elasticPassword=changeme
  6. spring.elasticsearch.bboss.default.elasticsearch.rest.hostNames=10.21.20.168:9200
  7. #spring.elasticsearch.bboss.default.elasticsearch.rest.hostNames=10.180.211.27:9280,10.180.211.27:9281,10.180.211.27:9282
  8. spring.elasticsearch.bboss.default.elasticsearch.dateFormat=yyyy.MM.dd
  9. spring.elasticsearch.bboss.default.elasticsearch.timeZone=Asia/Shanghai
  10. spring.elasticsearch.bboss.default.elasticsearch.ttl=2d
  11. #在控制台输出脚本调试开关showTemplate,false关闭,true打开,同时log4j至少是info级别
  12. spring.elasticsearch.bboss.default.elasticsearch.showTemplate=true
  13. spring.elasticsearch.bboss.default.elasticsearch.discoverHost=false
  14. ##default连接池配置
  15. spring.elasticsearch.bboss.default.http.timeoutConnection = 5000
  16. spring.elasticsearch.bboss.default.http.timeoutSocket = 5000
  17. spring.elasticsearch.bboss.default.http.connectionRequestTimeout=5000
  18. spring.elasticsearch.bboss.default.http.retryTime = 1
  19. spring.elasticsearch.bboss.default.http.maxLineLength = -1
  20. spring.elasticsearch.bboss.default.http.maxHeaderCount = 200
  21. spring.elasticsearch.bboss.default.http.maxTotal = 400
  22. spring.elasticsearch.bboss.default.http.defaultMaxPerRoute = 200
  23. spring.elasticsearch.bboss.default.http.keystore =
  24. spring.elasticsearch.bboss.default.http.keyPassword =
  25. # ssl 主机名称校验,是否采用default配置,
  26. # 如果指定为default,就采用DefaultHostnameVerifier,否则采用 SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER
  27. spring.elasticsearch.bboss.default.http.hostnameVerifier =
  28. ##logs集群配置
  29. spring.elasticsearch.bboss.logs.name = logs
  30. spring.elasticsearch.bboss.logs.elasticUser=elastic
  31. spring.elasticsearch.bboss.logs.elasticPassword=changeme
  32. spring.elasticsearch.bboss.logs.elasticsearch.rest.hostNames=127.0.0.1:9200
  33. #spring.elasticsearch.bboss.default.elasticsearch.rest.hostNames=10.180.211.27:9280,10.180.211.27:9281,10.180.211.27:9282
  34. spring.elasticsearch.bboss.logs.elasticsearch.dateFormat=yyyy.MM.dd
  35. spring.elasticsearch.bboss.logs.elasticsearch.timeZone=Asia/Shanghai
  36. spring.elasticsearch.bboss.logs.elasticsearch.ttl=2d
  37. #在控制台输出脚本调试开关showTemplate,false关闭,true打开,同时log4j至少是info级别
  38. spring.elasticsearch.bboss.logs.elasticsearch.showTemplate=true
  39. spring.elasticsearch.bboss.logs.elasticsearch.discoverHost=false
  40. ##logs集群对应的连接池配置
  41. spring.elasticsearch.bboss.logs.http.timeoutConnection = 5000
  42. spring.elasticsearch.bboss.logs.http.timeoutSocket = 5000
  43. spring.elasticsearch.bboss.logs.http.connectionRequestTimeout=5000
  44. spring.elasticsearch.bboss.logs.http.retryTime = 1
  45. spring.elasticsearch.bboss.logs.http.maxLineLength = -1
  46. spring.elasticsearch.bboss.logs.http.maxHeaderCount = 200
  47. spring.elasticsearch.bboss.logs.http.maxTotal = 400
  48. spring.elasticsearch.bboss.logs.http.defaultMaxPerRoute = 200
  49. # https证书配置
  50. spring.elasticsearch.bboss.logs.http.keystore =
  51. spring.elasticsearch.bboss.logs.http.keyPassword =
  52. # ssl 主机名称校验,是否采用default配置,
  53. # 如果指定为default,就采用DefaultHostnameVerifier,否则采用 SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER
  54. spring.elasticsearch.bboss.logs.http.hostnameVerifier =
  55. # dsl配置文件热加载扫描时间间隔,毫秒为单位,默认5秒扫描一次,<= 0时关闭扫描机制
  56. spring.elasticsearch.bboss.dslfile.refreshInterval = -1

配置说明:

上面配置了两个集群:default和logs

每个集群配置项的前缀为:spring.elasticsearch.bboss.集群名字,其中的集群名字是一个自定义的逻辑名称,用来在client api中引用集群。

注意:这里的集群名字是根据集群的作用命名的名字,和Elasticsearch本身的cluster.name没有关系,可自行根据需要命名

default集群的配置项前缀为:

  1. spring.elasticsearch.bboss.default

logs集群的配置项前缀为:

  1. spring.elasticsearch.bboss.logs

同时每个集群的配置项目里面必须包含name项目的配置

default集群name配置:

  1. spring.elasticsearch.bboss.default.name = default

logs集群name配置:

  1. ##logs集群配置
  2. spring.elasticsearch.bboss.logs.name = logs

4.1.2 yml配置(默认)

  1. spring:
  2. elasticsearch:
  3. bboss:
  4. default:
  5. name: default
  6. elasticUser: elastic
  7. elasticPassword: changeme
  8. elasticsearch:
  9. rest:
  10. hostNames: 127.0.0.1:9200
  11. ##hostNames: 127.0.0.1:9200,127.0.0.1:9201,127.0.0.1:9202
  12. dateFormat: yyyy.MM.dd
  13. timeZone: Asia/Shanghai
  14. ttl: 2d
  15. showTemplate: true
  16. discoverHost: false
  17. dslfile:
  18. refreshInterval: -1
  19. http:
  20. timeoutConnection: 5000
  21. timeoutSocket: 5000
  22. connectionRequestTimeout: 5000
  23. retryTime: 1
  24. maxLineLength: -1
  25. maxHeaderCount: 200
  26. maxTotal: 400
  27. defaultMaxPerRoute: 200
  28. soReuseAddress: false
  29. soKeepAlive: false
  30. timeToLive: 3600000
  31. keepAlive: 3600000
  32. keystore:
  33. keyPassword:
  34. hostnameVerifier:
  35. logs:
  36. name: logs
  37. elasticUser: elastic
  38. elasticPassword: changeme
  39. elasticsearch:
  40. rest:
  41. hostNames: 127.0.0.1:9200
  42. dateFormat: yyyy.MM.dd
  43. timeZone: Asia/Shanghai
  44. ttl: 2d
  45. showTemplate: true
  46. discoverHost: false
  47. dslfile:
  48. refreshInterval: -1
  49. http:
  50. timeoutConnection: 5000
  51. timeoutSocket: 5000
  52. connectionRequestTimeout: 5000
  53. retryTime: 1
  54. maxLineLength: -1
  55. maxHeaderCount: 200
  56. maxTotal: 400
  57. defaultMaxPerRoute: 200
  58. soReuseAddress: false
  59. soKeepAlive: false
  60. timeToLive: 3600000
  61. keepAlive: 3600000
  62. keystore:
  63. keyPassword:
  64. hostnameVerifier:

4.2 定义加载多es集群配置的spring boot Configuration类

新建类MultiESSTartConfigurer,声明分别对应两个不同集群的bboss工厂组件

  1. package org.bboss.elasticsearchtest.springboot;
  2. /*
  3. * Copyright 2008 biaoping.yin
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. import org.frameworkset.elasticsearch.ElasticSearchHelper;
  18. import org.frameworkset.elasticsearch.boot.BBossESStarter;
  19. import org.frameworkset.elasticsearch.client.ClientInterface;
  20. import org.springframework.boot.context.properties.ConfigurationProperties;
  21. import org.springframework.context.annotation.Bean;
  22. import org.springframework.context.annotation.Configuration;
  23. import org.springframework.context.annotation.Primary;
  24. import org.springframework.context.annotation.Profile;
  25. /**
  26. * 配置多个es集群
  27. * 指定多es数据源profile:multi-datasource
  28. */
  29. @Configuration
  30. public class MultiESSTartConfigurer {
  31. @Primary
  32. @Bean(initMethod = "start")
  33. @ConfigurationProperties("spring.elasticsearch.bboss.default")
  34. public BBossESStarter bbossESStarterDefault(){
  35. return new BBossESStarter();
  36. }
  37. @Bean(initMethod = "start")
  38. @ConfigurationProperties("spring.elasticsearch.bboss.logs")
  39. public BBossESStarter bbossESStarterLogs(){
  40. return new BBossESStarter();
  41. }
  42. }

说明:

MultiESSTartConfigurer通过以下两个方法分别加载default和logs两个es集群的配置

default集群配置加载

  1. @Primary
  2. @Bean(initMethod = "start")
  3. @ConfigurationProperties("spring.elasticsearch.bboss.default")
  4. public BBossESStarter bbossESStarterDefault()

logs集群配置加载

  1. @Bean(initMethod = "start")
  2. @ConfigurationProperties("spring.elasticsearch.bboss.logs")
  3. public BBossESStarter bbossESStarterLogs()

BBossESStarter bbossESStarterDefault 对应spring.elasticsearch.bboss.default配置的elasticsearch集群

BBossESStarter bbossESStarterLogs 对应spring.elasticsearch.bboss.logs配置的elasticsearch集群

两个组件的声明都是必须的,在程序中只要用其中任意一个都可以获取到两个对应集群的ClientInterface组件,具体看后面的示例。

4.3 定义多es集群测试用例

多es集群测试用例MultiBBossESStartersTestCase

  1. /*
  2. * Copyright 1999-2018 Alibaba Group Holding Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.bboss.elasticsearchtest.springboot;
  17. import org.frameworkset.elasticsearch.client.ClientInterface;
  18. import org.junit.Test;
  19. import org.junit.runner.RunWith;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.boot.test.context.SpringBootTest;
  22. import org.springframework.test.context.ActiveProfiles;
  23. import org.springframework.test.context.junit4.SpringRunner;
  24. /**
  25. * 多集群演示功能测试用例,spring boot配置项以spring.elasticsearch.bboss.集群名称开头,例如:
  26. * spring.elasticsearch.bboss.default 默认es集群
  27. * spring.elasticsearch.bboss.logs logs es集群
  28. * 两个集群通过 org.bboss.elasticsearchtest.springboot.MultiESSTartConfigurer加载
  29. * 对应的配置文件为application-multi-datasource.properties文件
  30. * 通过ActiveProfiles指定并激活多es集群配置:multi-datasource
  31. * @author yinbp [122054810@qq.com]
  32. */
  33. @RunWith(SpringRunner.class)
  34. @SpringBootTest(classes = Application.class)
  35. @ActiveProfiles("multi-datasource")
  36. public class MultiBBossESStartersTestCase {
  37. @Autowired
  38. private BBossESStarter bbossESStarterDefault;
  39. @Autowired
  40. MultiESDocumentCRUD multiESDocumentCRUD;
  41. @Test
  42. public void testMultiBBossESStarters() throws Exception {
  43. //验证环境,获取es状态
  44. // String response = bbossESStarterDefault.getRestClient().executeHttp("_cluster/state?pretty",ClientInterface.HTTP_GET);
  45. // System.out.println(response);
  46. //判断索引类型是否存在,false表示不存在,正常返回true表示存在
  47. boolean exist = bbossESStarterDefault.getRestClient().existIndiceType("twitter","tweet");
  48. System.out.println("default twitter/tweet:"+exist);
  49. //获取logs对应的Elasticsearch集群客户端,并进行existIndiceType操作
  50. exist = bbossESStarterDefault.getRestClient("logs").existIndiceType("twitter","tweet");
  51. System.out.println("logs twitter/tweet:"+exist);
  52. //获取logs对应的Elasticsearch集群客户端,判读索引是否存在,false表示不存在,正常返回true表示存在
  53. exist = bbossESStarterDefault.getRestClient("logs").existIndice("twitter");
  54. System.out.println("logs twitter:"+exist);
  55. //获取logs对应的Elasticsearch集群客户端,判断索引是否定义
  56. exist = bbossESStarterDefault.getRestClient("logs").existIndice("agentinfo");
  57. System.out.println("logs agentinfo:"+exist);
  58. }
  59. @Test
  60. public void testCRUD() throws Exception {
  61. //删除/创建文档索引表
  62. multiESDocumentCRUD.testCreateIndice();
  63. //添加/修改单个文档
  64. multiESDocumentCRUD.testAddAndUpdateDocument();
  65. //批量添加文档
  66. multiESDocumentCRUD.testBulkAddDocument();
  67. //检索文档
  68. multiESDocumentCRUD.testSearch();
  69. //批量修改文档
  70. multiESDocumentCRUD.testBulkUpdateDocument();
  71. //检索批量修改后的文档
  72. multiESDocumentCRUD.testSearch();
  73. //带list复杂参数的文档检索操作
  74. multiESDocumentCRUD.testSearchArray();
  75. //带from/size分页操作的文档检索操作
  76. multiESDocumentCRUD.testPagineSearch();
  77. //带sourcefilter的文档检索操作
  78. multiESDocumentCRUD.testSearchSourceFilter();
  79. multiESDocumentCRUD.updateDemoIndice();
  80. multiESDocumentCRUD.testBulkAddDocuments();
  81. }
  82. @Test
  83. public void testPerformaceCRUD() throws Exception {
  84. //删除/创建文档索引表
  85. multiESDocumentCRUD.testCreateIndice();
  86. multiESDocumentCRUD.testBulkAddDocuments();
  87. }
  88. }

直接通过junit运行上述测试用例即可。

其中

  1. BBossESStarter bbossESStarterDefault:实现由bboss提供,在直接在代码中MultiESSTartConfigurer 定义
  2. MultiESDocumentCRUD:各种增删改查操作实例,在demo工程中提供

5.完整的demo工程

https://github.com/bbossgroups/es_bboss_web

https://gitee.com/bboss/eshelloword-spring-boot-starter

https://github.com/bbossgroups/eshelloword-spring-boot-starter

6 开发交流

elasticsearch交流Q:166471282

elasticsearch:

img