├── README.md └── springboot ├── pom.xml ├── springboot.iml ├── src ├── main │ ├── java │ │ └── com │ │ │ └── mn │ │ │ └── springboot │ │ │ ├── SpringbootApplication.java │ │ │ ├── controller │ │ │ └── TeacherController.java │ │ │ ├── pojo │ │ │ ├── Student.java │ │ │ └── Teacher.java │ │ │ └── utils │ │ │ ├── GenericsUtils.java │ │ │ └── es │ │ │ ├── ESClient.java │ │ │ └── ESUtil.java │ └── resources │ │ ├── application.yml │ │ └── esmapper │ │ ├── student.xml │ │ └── teacher.xml └── test │ └── java │ └── com │ └── mn │ └── springboot │ └── SpringbootApplicationTests.java └── target ├── classes ├── application.yml ├── com │ └── mn │ │ └── springboot │ │ ├── SpringbootApplication.class │ │ ├── controller │ │ └── TeacherController.class │ │ ├── pojo │ │ ├── Student.class │ │ └── Teacher.class │ │ └── utils │ │ ├── GenericsUtils.class │ │ └── es │ │ ├── ESClient.class │ │ └── ESUtil.class └── esmapper │ ├── student.xml │ └── teacher.xml └── test-classes └── com └── mn └── springboot └── SpringbootApplicationTests.class /README.md: -------------------------------------------------------------------------------- 1 | # springboot-bboss-elasticsearch 2 | ##### https://blog.csdn.net/qq_31748587/article/details/84134864 3 | ##### 整合springboot+bboss+elasticsearch,实现java对es的操作 4 | ##### 需要修改的配置 5 | ##### application.yml文件: 6 | ##### basePath:对应mapper.xml文件存放的位置 7 | ##### indexs:es的全部索引,以逗号分隔 8 | ``` 9 | es: 10 | basePath: esmapper 11 | indexs: teacher,student 12 | ``` 13 | ##### 创建对应的mapper.xml文件即可 14 | -------------------------------------------------------------------------------- /springboot/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.mn 7 | springboot 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | springboot 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-test 35 | test 36 | 37 | 38 | 39 | com.bbossgroups.plugins 40 | bboss-elasticsearch-spring-boot-starter 41 | 5.1.5 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-maven-plugin 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /springboot/springboot.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /springboot/src/main/java/com/mn/springboot/SpringbootApplication.java: -------------------------------------------------------------------------------- 1 | package com.mn.springboot; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringbootApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringbootApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /springboot/src/main/java/com/mn/springboot/controller/TeacherController.java: -------------------------------------------------------------------------------- 1 | package com.mn.springboot.controller; 2 | 3 | import com.mn.springboot.pojo.Teacher; 4 | import com.mn.springboot.utils.es.ESClient; 5 | import com.mn.springboot.utils.es.ESUtil; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | @RestController 14 | public class TeacherController { 15 | @Autowired 16 | private ESUtil esUtil; 17 | 18 | @GetMapping("add") 19 | public String add(){ 20 | Teacher teacher = new Teacher(); 21 | teacher.setTeacherId("2"); 22 | teacher.setName("吴老师"); 23 | teacher.setSex("男"); 24 | teacher.setAge(50); 25 | Teacher teacher1 = new Teacher(); 26 | teacher1.setTeacherId("1"); 27 | teacher1.setName("王老师"); 28 | teacher1.setSex("女"); 29 | teacher1.setAge(20); 30 | List list = new ArrayList<>(); 31 | list.add(teacher); 32 | list.add(teacher1); 33 | esUtil.addOrUpdateDocuments("teacher",list); 34 | return "ok"; 35 | } 36 | 37 | @GetMapping("delete") 38 | public String delete(){ 39 | esUtil.deleteDocumentById("teacher","1"); 40 | return "ok"; 41 | } 42 | 43 | @GetMapping("get") 44 | public List get(){ 45 | Teacher teacher = new Teacher(); 46 | teacher.setTeacherId("2"); 47 | List t = esUtil.exec("teacher",teacher,"searchTeacher"); 48 | return t; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /springboot/src/main/java/com/mn/springboot/pojo/Student.java: -------------------------------------------------------------------------------- 1 | package com.mn.springboot.pojo;/* 2 | 3 | import com.frameworkset.orm.annotation.ESId; 4 | import org.frameworkset.elasticsearch.entity.ESBaseData; 5 | 6 | /** 7 | * 测试实体,可以从ESBaseData对象继承meta属性,检索时会将文档的一下meta属性设置到对象实例中 8 | */ 9 | 10 | import com.frameworkset.orm.annotation.ESId; 11 | import org.frameworkset.elasticsearch.entity.ESBaseData; 12 | 13 | public class Student extends ESBaseData { 14 | //设定文档标识字段 15 | @ESId 16 | private String studentId; 17 | private String name; 18 | private Integer age; 19 | private String sex; 20 | 21 | public String getStudentId() { 22 | return studentId; 23 | } 24 | 25 | public void setStudentId(String studentId) { 26 | this.studentId = studentId; 27 | } 28 | 29 | /** 当在mapping定义中指定了日期格式时,则需要指定以下两个注解,例如 30 | * 31 | "agentStarttime": { 32 | "type": "date",###指定多个日期格式 33 | "format":"yyyy-MM-dd HH:mm:ss.SSS||yyyy-MM-dd'T'HH:mm:ss.SSS||yyyy-MM-dd HH:mm:ss||epoch_millis" 34 | } 35 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS") 36 | @Column(dataformat = "yyyy-MM-dd HH:mm:ss.SSS") 37 | */ 38 | 39 | public String getName() { 40 | return name; 41 | } 42 | 43 | public void setName(String name) { 44 | this.name = name; 45 | } 46 | 47 | public Integer getAge() { 48 | return age; 49 | } 50 | 51 | public void setAge(Integer age) { 52 | this.age = age; 53 | } 54 | 55 | public String getSex() { 56 | return sex; 57 | } 58 | 59 | public void setSex(String sex) { 60 | this.sex = sex; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /springboot/src/main/java/com/mn/springboot/pojo/Teacher.java: -------------------------------------------------------------------------------- 1 | package com.mn.springboot.pojo;/* 2 | 3 | import com.frameworkset.orm.annotation.ESId; 4 | import org.frameworkset.elasticsearch.entity.ESBaseData; 5 | 6 | /** 7 | * 测试实体,可以从ESBaseData对象继承meta属性,检索时会将文档的一下meta属性设置到对象实例中 8 | */ 9 | 10 | import com.frameworkset.orm.annotation.ESId; 11 | import org.frameworkset.elasticsearch.entity.ESBaseData; 12 | 13 | public class Teacher extends ESBaseData { 14 | //设定文档标识字段 15 | @ESId 16 | private String teacherId; 17 | private String name; 18 | private Integer age; 19 | private String sex; 20 | /** 当在mapping定义中指定了日期格式时,则需要指定以下两个注解,例如 21 | * 22 | "agentStarttime": { 23 | "type": "date",###指定多个日期格式 24 | "format":"yyyy-MM-dd HH:mm:ss.SSS||yyyy-MM-dd'T'HH:mm:ss.SSS||yyyy-MM-dd HH:mm:ss||epoch_millis" 25 | } 26 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS") 27 | @Column(dataformat = "yyyy-MM-dd HH:mm:ss.SSS") 28 | */ 29 | public String getTeacherId() { 30 | return teacherId; 31 | } 32 | 33 | public void setTeacherId(String teacherId) { 34 | this.teacherId = teacherId; 35 | } 36 | 37 | public String getName() { 38 | return name; 39 | } 40 | 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | 45 | public Integer getAge() { 46 | return age; 47 | } 48 | 49 | public void setAge(Integer age) { 50 | this.age = age; 51 | } 52 | 53 | public String getSex() { 54 | return sex; 55 | } 56 | 57 | public void setSex(String sex) { 58 | this.sex = sex; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /springboot/src/main/java/com/mn/springboot/utils/GenericsUtils.java: -------------------------------------------------------------------------------- 1 | package com.mn.springboot.utils; 2 | 3 | import java.lang.reflect.ParameterizedType; 4 | import java.lang.reflect.Type; 5 | 6 | public class GenericsUtils { 7 | /** 8 | * 通过反射,获得定义Class时声明的父类的范型参数的类型. 如public BookManager extends 9 | * GenricManager 10 | * 11 | * @param clazz The class to introspect 12 | * @return the first generic declaration, or Object.class if cannot be determined 13 | */ 14 | public static Class getSuperClassGenricType(Class clazz) { 15 | return getSuperClassGenricType(clazz, 0); 16 | } 17 | 18 | /** 19 | * 通过反射,获得定义Class时声明的父类的范型参数的类型. 如public BookManager extends GenricManager 20 | * 21 | * @param clazz clazz The class to introspect 22 | * @param index the Index of the generic ddeclaration,start from 0. 23 | */ 24 | public static Class getSuperClassGenricType(Class clazz, int index) 25 | throws IndexOutOfBoundsException { 26 | Type genType = clazz.getGenericSuperclass(); 27 | if (!(genType instanceof ParameterizedType)) { 28 | return Object.class; 29 | } 30 | Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); 31 | if (index >= params.length || index < 0) { 32 | return Object.class; 33 | } 34 | if (!(params[index] instanceof Class)) { 35 | return Object.class; 36 | } 37 | return (Class) params[index]; 38 | } 39 | } -------------------------------------------------------------------------------- /springboot/src/main/java/com/mn/springboot/utils/es/ESClient.java: -------------------------------------------------------------------------------- 1 | package com.mn.springboot.utils.es; 2 | 3 | import org.frameworkset.elasticsearch.ElasticSearchHelper; 4 | import org.frameworkset.elasticsearch.client.ClientInterface; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.stereotype.Component; 7 | 8 | import java.util.Map; 9 | import java.util.concurrent.ConcurrentHashMap; 10 | 11 | /** 12 | * 管理es rest client组件实例 13 | */ 14 | @Component 15 | public class ESClient { 16 | //基础不需要xml 17 | private static ClientInterface restClient; 18 | private static String basePath; 19 | private static String indexs; 20 | //客户端 21 | private static Map client = new ConcurrentHashMap<>(); 22 | 23 | /** 24 | * 获取操作默认的es集群的客户端工具组件 25 | * @return 26 | */ 27 | public static ClientInterface restClient(){ 28 | if(restClient == null) { 29 | synchronized (ClientInterface.class) { 30 | if (restClient == null) { 31 | restClient = ElasticSearchHelper.getRestClientUtil(); 32 | } 33 | } 34 | } 35 | return restClient; 36 | } 37 | 38 | /** 39 | * 获取操作配置文件的es集群的客户端工具组件 40 | * @return 41 | */ 42 | public static ClientInterface restClient(String index){ 43 | if(client.isEmpty()){ 44 | String[] indexArr = indexs.split(","); 45 | for(int i=0;i void addOrUpdateDocuments(String index,List list){ 30 | //获取文档的客户端对象,单实例多线程安全 31 | ClientInterface clientUtil = ESClient.restClient(); 32 | //向固定index添加或者修改文档,id,否则做添加文档操作,返回处理结果 33 | //索引表 索引类型 34 | clientUtil.addDocuments(index,index,list); 35 | } 36 | /** 37 | * 获取文档 38 | */ 39 | public String getDocumentById(String index,String id){ 40 | //获取文档的客户端对象,单实例多线程安全 41 | ClientInterface clientUtil = ESClient.restClient(); 42 | //索引表 索引类型 id 43 | String res = clientUtil.getDocument(index,index,id); 44 | return res; 45 | } 46 | /** 47 | * 获取文档 48 | */ 49 | public T getDocumentById(String index,String id,Class t){ 50 | //获取文档的客户端对象,单实例多线程安全 51 | ClientInterface clientUtil = ESClient.restClient(); 52 | //索引表 索引类型 id 对象 53 | return clientUtil.getDocument(index,index,id,t); 54 | } 55 | /** 56 | * 删除文档 57 | */ 58 | public void deleteDocumentById(String index,String id){ 59 | //获取文档的客户端对象,单实例多线程安全 60 | ClientInterface clientUtil = ESClient.restClient(); 61 | //索引表 索引类型 id 对象 62 | clientUtil.deleteDocument(index,index,id); 63 | } 64 | /** 65 | * 删除文档 66 | */ 67 | public void deleteDocumentByIds(String index,String[] ids){ 68 | //获取文档的客户端对象,单实例多线程安全 69 | ClientInterface clientUtil = ESClient.restClient(); 70 | StringBuilder builder = new StringBuilder(); 71 | String[] var5 = ids; 72 | for(int i = 0; i < ids.length; ++i) { 73 | String id = ids[i]; 74 | builder.append("{ \"delete\" : { \"_index\" : \"").append(index).append("\", \"_type\" : \"").append(index).append("\", \"_id\" : \"").append(id).append("\" } }\n"); 75 | } 76 | //索引表 索引类型 id 对象 77 | clientUtil.executeHttp("_bulk",builder.toString(),"post"); 78 | } 79 | 80 | /** 81 | * 通过mapper文件执行查询语句 82 | * @param index 索引 83 | * @param params 传递的参数 84 | * @param dsl 对应mapper文件的name 85 | */ 86 | public List exec(String index,T params,String dsl){ 87 | //获取索引对应的客户端 88 | ClientInterface clientUtil = ESClient.restClient(index); 89 | //设定查询条件,通过map传递变量参数值,key对于dsl中的变量名称 90 | //执行查询,index为索引表,_search为检索操作action 91 | //使用反射获取Class 92 | Class clazz = GenericsUtils.getSuperClassGenricType(params.getClass()); 93 | ESDatas esDatas = //ESDatas包含当前检索的记录集合,最多1000条记录,由dsl中的size属性指定 94 | clientUtil.searchList(index+"/_search",//demo为索引表,_search为检索操作action 95 | dsl,//esmapper/xxx.xml中定义的dsl语句的name 96 | params,//变量参数 97 | clazz);//返回的文档封装对象类型 98 | //获取结果对象列表,最多返回1000条记录 99 | List list = esDatas.getDatas(); 100 | //获取总记录数 101 | long totalSize = esDatas.getTotalSize(); 102 | return list; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /springboot/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8888 3 | spring: 4 | elasticsearch: 5 | bboss: 6 | elasticUser: 7 | elasticPassword: 8 | elasticsearch: 9 | rest: 10 | hostNames: 127.0.0.1:9200 11 | dateFormat: yyyy-MM-dd hh:mm:ss 12 | timeZone: Asia/Shanghai 13 | ttl: 2d 14 | showTemplate: true 15 | discoverHost: false 16 | dslfile: 17 | refreshInterval: -1 18 | http: 19 | timeoutConnection: 400000 20 | timeoutSocket: 400000 21 | connectionRequestTimeout: 400000 22 | retryTime: 1 23 | maxLineLength: -1 24 | maxHeaderCount: 200 25 | maxTotal: 400 26 | defaultMaxPerRoute: 200 27 | soReuseAddress: false 28 | soKeepAlive: false 29 | timeToLive: 3600000 30 | keepAlive: 3600000 31 | keystore: 32 | keyPassword: 33 | hostnameVerifier: 34 | es: 35 | basePath: esmapper/ 36 | indexs: teacher,student 37 | -------------------------------------------------------------------------------- /springboot/src/main/resources/esmapper/student.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 21 | 22 | 23 | 33 | 34 | 57 | 58 | 59 | 60 | 61 | 86 | 87 | 90 | 91 | 92 | 115 | 116 | 117 | 127 | 128 | 153 | 154 | 155 | 165 | 166 | 189 | 190 | 191 | 210 | 211 | 0) ##设置includes filter 215 | "includes": [ 216 | #foreach($include in $includes) 217 | #if($velocityCount > 0),#end "$include" 218 | #end 219 | ] 220 | #if($excludes && $excludes.size() > 0),#end ##如果还存在排斥字段,则需要加一个逗号 221 | #end 222 | #if($excludes && $excludes.size() > 0) ##设置excludes filter 223 | "excludes": [ 224 | #foreach($exclude in $excludes) 225 | #if($velocityCount > 0),#end "$exclude" 226 | #end 227 | ] 228 | #end 229 | }, 230 | #end 231 | "query": { 232 | "bool": { 233 | "filter": [ 234 | #if($applicationNames && $applicationNames.size() > 0) ##只有传递了需要检索的应用名称集合,才需要添加下面的条件 235 | { ## 多值检索,查找多个应用名称对应的文档记录 236 | "terms": { 237 | "applicationName.keyword":[ 238 | #foreach($applicationName in $applicationNames) 239 | #if($velocityCount > 0),#end "$applicationName" 240 | #end 241 | ] 242 | } 243 | }, 244 | #end 245 | { ## 时间范围检索,返回对应时间范围内的记录,接受long型的值 246 | "range": { 247 | "agentStarttime": { 248 | "gte": #[startTime],##统计开始时间 249 | "lt": #[endTime] ##统计截止时间 250 | } 251 | } 252 | } 253 | ] 254 | } 255 | }, 256 | ## 最多返回pageSize参数对应记录条数 257 | "size":#[pageSize] 258 | }]]> 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 304 | 305 | 306 | 310 | 311 | 318 | 319 | 320 | 321 | 322 | goodsId], 327 | "rules":[ 328 | #foreach($rule in $dynamicPriceTemplate.rules) 329 | #if($velocityCount > 0),#end 330 | { 331 | "ruleId": #[dynamicPriceTemplate->rules[$velocityCount]->ruleId], 332 | "ruleCount": #[dynamicPriceTemplate->rules[$velocityCount]->ruleCount], 333 | "ruleExist": #[dynamicPriceTemplate->rules[$velocityCount]->ruleExist] 334 | } 335 | #end 336 | ] 337 | } 338 | ]]> 339 | 340 | 341 | 342 | goodsId], 347 | "rules":[ 348 | #foreach($rule in $dynamicPriceTemplate.rules) 349 | #if($velocityCount > 0),#end 350 | { 351 | 352 | "ruleId": "$rule.ruleId", 353 | "ruleCount": $rule.ruleCount, 354 | "ruleExist": $rule.ruleExist 355 | 356 | } 357 | #end 358 | ] 359 | } 360 | ]]> 361 | 362 | 363 | 374 | 375 | 376 | 377 | goodsId], 382 | "rules":[ 383 | #foreach($rule in $dynamicPriceTemplate.rules) 384 | #[dynamicPriceTemplate->rules[$velocityCount],serialJson=true] ## 通过属性serialJson指示框架直接将对象序列化为json数据 385 | #if($velocityCount != ($dynamicPriceTemplate.rules.size() - 1)),#end 386 | #end 387 | ] 388 | } 389 | ]]> 390 | 391 | 392 | goodName,escapeCount=2];#*在脚本中,含有特殊字符的goodName需要转义2次*# 411 | ctx._source.goodsId = #[dynamicPriceTemplate->goodsId]; 412 | ctx._source.dynamicPriceTemplate.goodsId = params.goodsId; 413 | ctx._source.rules = params.rules 414 | """, 415 | @{scriptPianduan2} 416 | } 417 | }]]> 418 | 419 | 420 | 0),#end 424 | { "match": { "$item.key": "$item.value" } } 425 | #end 426 | ]]> 427 | 428 | 429 | 430 | >遍历实例,可以通过#[]绑定变量对值中存在的特殊字符进行转义处理 432 | #foreach($item in $softTypeMap.entrySet()) 433 | #if($item.value) 434 | #if($velocityCount > 0),#end 435 | { "match": { "$item.key": #[softTypeMap[$item.key],serialJson=true] } } 436 | #end 437 | #end 438 | ]]> 439 | 440 | 441 | 442 | 0),#end 450 | { "match": 451 | { 452 | #if($item.value) 453 | "$item.key": 454 | [ 455 | #foreach($applicationName in $item.value) 456 | #if($velocityCount > 0),#end #[softTypeMap[$item.key][$velocityCount]] 457 | #end 458 | ] 459 | #end 460 | } 461 | } 462 | #end 463 | ] 464 | } 465 | } 466 | } 467 | ]]> 468 | 469 | 470 | 471 | 0),#end 480 | { "match": { "$item.key": #[$mustShouldMap[$item.key][$velocityCount]] } } 481 | #end 482 | ] 483 | } 484 | } 485 | #end 486 | #end 487 | ]]> 488 | 489 | -------------------------------------------------------------------------------- /springboot/src/main/resources/esmapper/teacher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 21 | 22 | 23 | 33 | 34 | 57 | 58 | 59 | 60 | 61 | 86 | 87 | 90 | 91 | 92 | 115 | 116 | 117 | 127 | 128 | 153 | 154 | 155 | 165 | 166 | 189 | 190 | 191 | 210 | 211 | 0) ##设置includes filter 215 | "includes": [ 216 | #foreach($include in $includes) 217 | #if($velocityCount > 0),#end "$include" 218 | #end 219 | ] 220 | #if($excludes && $excludes.size() > 0),#end ##如果还存在排斥字段,则需要加一个逗号 221 | #end 222 | #if($excludes && $excludes.size() > 0) ##设置excludes filter 223 | "excludes": [ 224 | #foreach($exclude in $excludes) 225 | #if($velocityCount > 0),#end "$exclude" 226 | #end 227 | ] 228 | #end 229 | }, 230 | #end 231 | "query": { 232 | "bool": { 233 | "filter": [ 234 | #if($applicationNames && $applicationNames.size() > 0) ##只有传递了需要检索的应用名称集合,才需要添加下面的条件 235 | { ## 多值检索,查找多个应用名称对应的文档记录 236 | "terms": { 237 | "applicationName.keyword":[ 238 | #foreach($applicationName in $applicationNames) 239 | #if($velocityCount > 0),#end "$applicationName" 240 | #end 241 | ] 242 | } 243 | }, 244 | #end 245 | { ## 时间范围检索,返回对应时间范围内的记录,接受long型的值 246 | "range": { 247 | "agentStarttime": { 248 | "gte": #[startTime],##统计开始时间 249 | "lt": #[endTime] ##统计截止时间 250 | } 251 | } 252 | } 253 | ] 254 | } 255 | }, 256 | ## 最多返回pageSize参数对应记录条数 257 | "size":#[pageSize] 258 | }]]> 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 304 | 305 | 306 | 310 | 311 | 318 | 319 | 320 | 321 | 322 | goodsId], 327 | "rules":[ 328 | #foreach($rule in $dynamicPriceTemplate.rules) 329 | #if($velocityCount > 0),#end 330 | { 331 | "ruleId": #[dynamicPriceTemplate->rules[$velocityCount]->ruleId], 332 | "ruleCount": #[dynamicPriceTemplate->rules[$velocityCount]->ruleCount], 333 | "ruleExist": #[dynamicPriceTemplate->rules[$velocityCount]->ruleExist] 334 | } 335 | #end 336 | ] 337 | } 338 | ]]> 339 | 340 | 341 | 342 | goodsId], 347 | "rules":[ 348 | #foreach($rule in $dynamicPriceTemplate.rules) 349 | #if($velocityCount > 0),#end 350 | { 351 | 352 | "ruleId": "$rule.ruleId", 353 | "ruleCount": $rule.ruleCount, 354 | "ruleExist": $rule.ruleExist 355 | 356 | } 357 | #end 358 | ] 359 | } 360 | ]]> 361 | 362 | 363 | 374 | 375 | 376 | 377 | goodsId], 382 | "rules":[ 383 | #foreach($rule in $dynamicPriceTemplate.rules) 384 | #[dynamicPriceTemplate->rules[$velocityCount],serialJson=true] ## 通过属性serialJson指示框架直接将对象序列化为json数据 385 | #if($velocityCount != ($dynamicPriceTemplate.rules.size() - 1)),#end 386 | #end 387 | ] 388 | } 389 | ]]> 390 | 391 | 392 | goodName,escapeCount=2];#*在脚本中,含有特殊字符的goodName需要转义2次*# 411 | ctx._source.goodsId = #[dynamicPriceTemplate->goodsId]; 412 | ctx._source.dynamicPriceTemplate.goodsId = params.goodsId; 413 | ctx._source.rules = params.rules 414 | """, 415 | @{scriptPianduan2} 416 | } 417 | }]]> 418 | 419 | 420 | 0),#end 424 | { "match": { "$item.key": "$item.value" } } 425 | #end 426 | ]]> 427 | 428 | 429 | 430 | >遍历实例,可以通过#[]绑定变量对值中存在的特殊字符进行转义处理 432 | #foreach($item in $softTypeMap.entrySet()) 433 | #if($item.value) 434 | #if($velocityCount > 0),#end 435 | { "match": { "$item.key": #[softTypeMap[$item.key],serialJson=true] } } 436 | #end 437 | #end 438 | ]]> 439 | 440 | 441 | 442 | 0),#end 450 | { "match": 451 | { 452 | #if($item.value) 453 | "$item.key": 454 | [ 455 | #foreach($applicationName in $item.value) 456 | #if($velocityCount > 0),#end #[softTypeMap[$item.key][$velocityCount]] 457 | #end 458 | ] 459 | #end 460 | } 461 | } 462 | #end 463 | ] 464 | } 465 | } 466 | } 467 | ]]> 468 | 469 | 470 | 471 | 0),#end 480 | { "match": { "$item.key": #[$mustShouldMap[$item.key][$velocityCount]] } } 481 | #end 482 | ] 483 | } 484 | } 485 | #end 486 | #end 487 | ]]> 488 | 489 | -------------------------------------------------------------------------------- /springboot/src/test/java/com/mn/springboot/SpringbootApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.mn.springboot; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringbootApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot/target/classes/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8888 3 | spring: 4 | elasticsearch: 5 | bboss: 6 | elasticUser: 7 | elasticPassword: 8 | elasticsearch: 9 | rest: 10 | hostNames: 127.0.0.1:9200 11 | dateFormat: yyyy-MM-dd hh:mm:ss 12 | timeZone: Asia/Shanghai 13 | ttl: 2d 14 | showTemplate: true 15 | discoverHost: false 16 | dslfile: 17 | refreshInterval: -1 18 | http: 19 | timeoutConnection: 400000 20 | timeoutSocket: 400000 21 | connectionRequestTimeout: 400000 22 | retryTime: 1 23 | maxLineLength: -1 24 | maxHeaderCount: 200 25 | maxTotal: 400 26 | defaultMaxPerRoute: 200 27 | soReuseAddress: false 28 | soKeepAlive: false 29 | timeToLive: 3600000 30 | keepAlive: 3600000 31 | keystore: 32 | keyPassword: 33 | hostnameVerifier: 34 | es: 35 | basePath: esmapper/ 36 | indexs: teacher,student 37 | management: 38 | port: 54001 39 | endpoints: 40 | web: 41 | exposure: 42 | include: /* 43 | -------------------------------------------------------------------------------- /springboot/target/classes/com/mn/springboot/SpringbootApplication.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsFive/springboot-bboss-elasticsearch/8f8bcf1cb57ed9a6b4b77e620b0694cac4e324d6/springboot/target/classes/com/mn/springboot/SpringbootApplication.class -------------------------------------------------------------------------------- /springboot/target/classes/com/mn/springboot/controller/TeacherController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsFive/springboot-bboss-elasticsearch/8f8bcf1cb57ed9a6b4b77e620b0694cac4e324d6/springboot/target/classes/com/mn/springboot/controller/TeacherController.class -------------------------------------------------------------------------------- /springboot/target/classes/com/mn/springboot/pojo/Student.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsFive/springboot-bboss-elasticsearch/8f8bcf1cb57ed9a6b4b77e620b0694cac4e324d6/springboot/target/classes/com/mn/springboot/pojo/Student.class -------------------------------------------------------------------------------- /springboot/target/classes/com/mn/springboot/pojo/Teacher.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsFive/springboot-bboss-elasticsearch/8f8bcf1cb57ed9a6b4b77e620b0694cac4e324d6/springboot/target/classes/com/mn/springboot/pojo/Teacher.class -------------------------------------------------------------------------------- /springboot/target/classes/com/mn/springboot/utils/GenericsUtils.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsFive/springboot-bboss-elasticsearch/8f8bcf1cb57ed9a6b4b77e620b0694cac4e324d6/springboot/target/classes/com/mn/springboot/utils/GenericsUtils.class -------------------------------------------------------------------------------- /springboot/target/classes/com/mn/springboot/utils/es/ESClient.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsFive/springboot-bboss-elasticsearch/8f8bcf1cb57ed9a6b4b77e620b0694cac4e324d6/springboot/target/classes/com/mn/springboot/utils/es/ESClient.class -------------------------------------------------------------------------------- /springboot/target/classes/com/mn/springboot/utils/es/ESUtil.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsFive/springboot-bboss-elasticsearch/8f8bcf1cb57ed9a6b4b77e620b0694cac4e324d6/springboot/target/classes/com/mn/springboot/utils/es/ESUtil.class -------------------------------------------------------------------------------- /springboot/target/classes/esmapper/student.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 21 | 22 | 23 | 33 | 34 | 57 | 58 | 59 | 60 | 61 | 86 | 87 | 90 | 91 | 92 | 115 | 116 | 117 | 127 | 128 | 153 | 154 | 155 | 165 | 166 | 189 | 190 | 191 | 210 | 211 | 0) ##设置includes filter 215 | "includes": [ 216 | #foreach($include in $includes) 217 | #if($velocityCount > 0),#end "$include" 218 | #end 219 | ] 220 | #if($excludes && $excludes.size() > 0),#end ##如果还存在排斥字段,则需要加一个逗号 221 | #end 222 | #if($excludes && $excludes.size() > 0) ##设置excludes filter 223 | "excludes": [ 224 | #foreach($exclude in $excludes) 225 | #if($velocityCount > 0),#end "$exclude" 226 | #end 227 | ] 228 | #end 229 | }, 230 | #end 231 | "query": { 232 | "bool": { 233 | "filter": [ 234 | #if($applicationNames && $applicationNames.size() > 0) ##只有传递了需要检索的应用名称集合,才需要添加下面的条件 235 | { ## 多值检索,查找多个应用名称对应的文档记录 236 | "terms": { 237 | "applicationName.keyword":[ 238 | #foreach($applicationName in $applicationNames) 239 | #if($velocityCount > 0),#end "$applicationName" 240 | #end 241 | ] 242 | } 243 | }, 244 | #end 245 | { ## 时间范围检索,返回对应时间范围内的记录,接受long型的值 246 | "range": { 247 | "agentStarttime": { 248 | "gte": #[startTime],##统计开始时间 249 | "lt": #[endTime] ##统计截止时间 250 | } 251 | } 252 | } 253 | ] 254 | } 255 | }, 256 | ## 最多返回pageSize参数对应记录条数 257 | "size":#[pageSize] 258 | }]]> 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 304 | 305 | 306 | 310 | 311 | 318 | 319 | 320 | 321 | 322 | goodsId], 327 | "rules":[ 328 | #foreach($rule in $dynamicPriceTemplate.rules) 329 | #if($velocityCount > 0),#end 330 | { 331 | "ruleId": #[dynamicPriceTemplate->rules[$velocityCount]->ruleId], 332 | "ruleCount": #[dynamicPriceTemplate->rules[$velocityCount]->ruleCount], 333 | "ruleExist": #[dynamicPriceTemplate->rules[$velocityCount]->ruleExist] 334 | } 335 | #end 336 | ] 337 | } 338 | ]]> 339 | 340 | 341 | 342 | goodsId], 347 | "rules":[ 348 | #foreach($rule in $dynamicPriceTemplate.rules) 349 | #if($velocityCount > 0),#end 350 | { 351 | 352 | "ruleId": "$rule.ruleId", 353 | "ruleCount": $rule.ruleCount, 354 | "ruleExist": $rule.ruleExist 355 | 356 | } 357 | #end 358 | ] 359 | } 360 | ]]> 361 | 362 | 363 | 374 | 375 | 376 | 377 | goodsId], 382 | "rules":[ 383 | #foreach($rule in $dynamicPriceTemplate.rules) 384 | #[dynamicPriceTemplate->rules[$velocityCount],serialJson=true] ## 通过属性serialJson指示框架直接将对象序列化为json数据 385 | #if($velocityCount != ($dynamicPriceTemplate.rules.size() - 1)),#end 386 | #end 387 | ] 388 | } 389 | ]]> 390 | 391 | 392 | goodName,escapeCount=2];#*在脚本中,含有特殊字符的goodName需要转义2次*# 411 | ctx._source.goodsId = #[dynamicPriceTemplate->goodsId]; 412 | ctx._source.dynamicPriceTemplate.goodsId = params.goodsId; 413 | ctx._source.rules = params.rules 414 | """, 415 | @{scriptPianduan2} 416 | } 417 | }]]> 418 | 419 | 420 | 0),#end 424 | { "match": { "$item.key": "$item.value" } } 425 | #end 426 | ]]> 427 | 428 | 429 | 430 | >遍历实例,可以通过#[]绑定变量对值中存在的特殊字符进行转义处理 432 | #foreach($item in $softTypeMap.entrySet()) 433 | #if($item.value) 434 | #if($velocityCount > 0),#end 435 | { "match": { "$item.key": #[softTypeMap[$item.key],serialJson=true] } } 436 | #end 437 | #end 438 | ]]> 439 | 440 | 441 | 442 | 0),#end 450 | { "match": 451 | { 452 | #if($item.value) 453 | "$item.key": 454 | [ 455 | #foreach($applicationName in $item.value) 456 | #if($velocityCount > 0),#end #[softTypeMap[$item.key][$velocityCount]] 457 | #end 458 | ] 459 | #end 460 | } 461 | } 462 | #end 463 | ] 464 | } 465 | } 466 | } 467 | ]]> 468 | 469 | 470 | 471 | 0),#end 480 | { "match": { "$item.key": #[$mustShouldMap[$item.key][$velocityCount]] } } 481 | #end 482 | ] 483 | } 484 | } 485 | #end 486 | #end 487 | ]]> 488 | 489 | -------------------------------------------------------------------------------- /springboot/target/classes/esmapper/teacher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 21 | 22 | 23 | 33 | 34 | 57 | 58 | 59 | 60 | 61 | 86 | 87 | 90 | 91 | 92 | 115 | 116 | 117 | 127 | 128 | 153 | 154 | 155 | 165 | 166 | 189 | 190 | 191 | 210 | 211 | 0) ##设置includes filter 215 | "includes": [ 216 | #foreach($include in $includes) 217 | #if($velocityCount > 0),#end "$include" 218 | #end 219 | ] 220 | #if($excludes && $excludes.size() > 0),#end ##如果还存在排斥字段,则需要加一个逗号 221 | #end 222 | #if($excludes && $excludes.size() > 0) ##设置excludes filter 223 | "excludes": [ 224 | #foreach($exclude in $excludes) 225 | #if($velocityCount > 0),#end "$exclude" 226 | #end 227 | ] 228 | #end 229 | }, 230 | #end 231 | "query": { 232 | "bool": { 233 | "filter": [ 234 | #if($applicationNames && $applicationNames.size() > 0) ##只有传递了需要检索的应用名称集合,才需要添加下面的条件 235 | { ## 多值检索,查找多个应用名称对应的文档记录 236 | "terms": { 237 | "applicationName.keyword":[ 238 | #foreach($applicationName in $applicationNames) 239 | #if($velocityCount > 0),#end "$applicationName" 240 | #end 241 | ] 242 | } 243 | }, 244 | #end 245 | { ## 时间范围检索,返回对应时间范围内的记录,接受long型的值 246 | "range": { 247 | "agentStarttime": { 248 | "gte": #[startTime],##统计开始时间 249 | "lt": #[endTime] ##统计截止时间 250 | } 251 | } 252 | } 253 | ] 254 | } 255 | }, 256 | ## 最多返回pageSize参数对应记录条数 257 | "size":#[pageSize] 258 | }]]> 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 304 | 305 | 306 | 310 | 311 | 318 | 319 | 320 | 321 | 322 | goodsId], 327 | "rules":[ 328 | #foreach($rule in $dynamicPriceTemplate.rules) 329 | #if($velocityCount > 0),#end 330 | { 331 | "ruleId": #[dynamicPriceTemplate->rules[$velocityCount]->ruleId], 332 | "ruleCount": #[dynamicPriceTemplate->rules[$velocityCount]->ruleCount], 333 | "ruleExist": #[dynamicPriceTemplate->rules[$velocityCount]->ruleExist] 334 | } 335 | #end 336 | ] 337 | } 338 | ]]> 339 | 340 | 341 | 342 | goodsId], 347 | "rules":[ 348 | #foreach($rule in $dynamicPriceTemplate.rules) 349 | #if($velocityCount > 0),#end 350 | { 351 | 352 | "ruleId": "$rule.ruleId", 353 | "ruleCount": $rule.ruleCount, 354 | "ruleExist": $rule.ruleExist 355 | 356 | } 357 | #end 358 | ] 359 | } 360 | ]]> 361 | 362 | 363 | 374 | 375 | 376 | 377 | goodsId], 382 | "rules":[ 383 | #foreach($rule in $dynamicPriceTemplate.rules) 384 | #[dynamicPriceTemplate->rules[$velocityCount],serialJson=true] ## 通过属性serialJson指示框架直接将对象序列化为json数据 385 | #if($velocityCount != ($dynamicPriceTemplate.rules.size() - 1)),#end 386 | #end 387 | ] 388 | } 389 | ]]> 390 | 391 | 392 | goodName,escapeCount=2];#*在脚本中,含有特殊字符的goodName需要转义2次*# 411 | ctx._source.goodsId = #[dynamicPriceTemplate->goodsId]; 412 | ctx._source.dynamicPriceTemplate.goodsId = params.goodsId; 413 | ctx._source.rules = params.rules 414 | """, 415 | @{scriptPianduan2} 416 | } 417 | }]]> 418 | 419 | 420 | 0),#end 424 | { "match": { "$item.key": "$item.value" } } 425 | #end 426 | ]]> 427 | 428 | 429 | 430 | >遍历实例,可以通过#[]绑定变量对值中存在的特殊字符进行转义处理 432 | #foreach($item in $softTypeMap.entrySet()) 433 | #if($item.value) 434 | #if($velocityCount > 0),#end 435 | { "match": { "$item.key": #[softTypeMap[$item.key],serialJson=true] } } 436 | #end 437 | #end 438 | ]]> 439 | 440 | 441 | 442 | 0),#end 450 | { "match": 451 | { 452 | #if($item.value) 453 | "$item.key": 454 | [ 455 | #foreach($applicationName in $item.value) 456 | #if($velocityCount > 0),#end #[softTypeMap[$item.key][$velocityCount]] 457 | #end 458 | ] 459 | #end 460 | } 461 | } 462 | #end 463 | ] 464 | } 465 | } 466 | } 467 | ]]> 468 | 469 | 470 | 471 | 0),#end 480 | { "match": { "$item.key": #[$mustShouldMap[$item.key][$velocityCount]] } } 481 | #end 482 | ] 483 | } 484 | } 485 | #end 486 | #end 487 | ]]> 488 | 489 | -------------------------------------------------------------------------------- /springboot/target/test-classes/com/mn/springboot/SpringbootApplicationTests.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsFive/springboot-bboss-elasticsearch/8f8bcf1cb57ed9a6b4b77e620b0694cac4e324d6/springboot/target/test-classes/com/mn/springboot/SpringbootApplicationTests.class --------------------------------------------------------------------------------