├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── pom.xml └── src ├── main ├── java │ └── org │ │ └── bboss │ │ ├── elasticsearchtest │ │ ├── HighlightSearch.java │ │ ├── HighlightSearch7.java │ │ ├── byquery │ │ │ └── DeleteUdateByQuery.java │ │ ├── crud │ │ │ ├── Demo.java │ │ │ ├── DemoWithES7Index.java │ │ │ ├── DemoWithES7IndexSimple.java │ │ │ ├── DemoWithES7IndexUseBatch.java │ │ │ ├── DemoWithESIndex.java │ │ │ ├── DocumentCRUD.java │ │ │ ├── DocumentCRUD7.java │ │ │ ├── FieldDemo.java │ │ │ ├── MetaDemo.java │ │ │ ├── NewDemo.java │ │ │ ├── NewDemoPersistent.java │ │ │ └── UUIDDemo.java │ │ ├── script │ │ │ ├── DynamicPriceTemplate.java │ │ │ ├── Rule.java │ │ │ ├── ScriptImpl.java │ │ │ └── ScriptImpl7.java │ │ ├── searchafter │ │ │ └── DocumentSearchAfter.java │ │ └── textembedding │ │ │ └── TextEmbedding.java │ │ └── eshelloword │ │ ├── Helloworld.java │ │ └── MultiESBooter.java └── resources │ ├── application.basicauth.properties │ ├── application.kerberos.properties │ ├── application.properties │ ├── application.properties.example │ ├── application.properties.multicluster │ ├── application.properties.searchguardssl │ ├── applicationtwo.properties │ ├── dbbulktest.xml │ ├── esmapper │ ├── Client_Info.xml │ ├── arryaymapping.xml │ ├── badquery.xml │ ├── byquery.xml │ ├── cluster.xml │ ├── demo.xml │ ├── demo233.xml │ ├── demo7.xml │ ├── dsl.xml │ ├── dslcacheexample.xml │ ├── indexparentchild.xml │ ├── joinparentchild.xml │ ├── joinparentchild7.xml │ ├── license.xml │ ├── matchPhrasePrefixQuery.xml │ ├── morelikethis.xml │ ├── orderQuery.xml │ ├── outpianduanref.xml │ ├── pianduan.xml │ ├── score.xml │ ├── scroll.xml │ ├── searchafter.xml │ ├── searchdsl.xml │ ├── sql.xml │ ├── testagg.xml │ └── textembedding.xml │ ├── log4j2.xml │ └── searchguard │ ├── certs │ ├── client-certificates.readme │ ├── kirk-keystore.jks │ ├── kirk.key │ ├── kirk.pem │ ├── kirk.pfx │ ├── node1.key │ ├── node1.pem │ ├── node1_elasticsearch_config_snippet.yml │ ├── node1_http.key │ ├── node1_http.pem │ ├── root-ca.key │ ├── root-ca.pem │ ├── root-ca.readme │ ├── spock.key │ └── spock.pem │ └── truststore.jks └── test └── java └── org └── bboss └── elasticsearchtest ├── HighlightSearch7Test.java ├── HighlightSearchTest.java ├── MatchPhrasePrefixQueryTest.java ├── TestInit.java ├── aggs └── TestTermAgg.java ├── aws ├── AWSClient.java ├── AWSRequestSigningApacheInterceptor.java └── HttpClientBuilderCallbackDemo.java ├── badquery └── TestBadQuery.java ├── bulkprocessor ├── PersistentBulkProcessor.java ├── PositionUrl.java ├── TestBulkProcessor.java ├── TestBulkProcessor7x.java ├── TestBulkProcessor7x_Size.java └── TestObject.java ├── cluster └── TestClusterSetting.java ├── crud ├── DeleteUdateByQueryTest.java ├── DocumentCRUD7Test.java ├── DocumentCRUDTest.java ├── DocumentSearchAfterTest.java ├── TestSearchGuard.java └── TestSlowDslCallback.java ├── custominit ├── CustormInitAndBoot.java ├── CustormInitAndBoot1.java └── CustormInitAndBootKerberosAuth.java ├── db2es ├── CustomObject.java ├── ESJdbcTest.java.example ├── ScheduleImportTaskTest.java └── TestObject.java ├── dsl ├── DslTest.java └── TestPianduan.java ├── forcemerge └── ForceMergeTest.java ├── index ├── AliasTest.java ├── GetAllIndices.java ├── ReindexTest.java ├── SmartCN.java └── UpdateIndiceMapping.java ├── jointype ├── Answer.java ├── Comment.java ├── JoinTypeTest.java ├── JoinTypeTest7.java └── Question.java ├── license └── ImportLicense.java ├── mapping └── MappingTest.java ├── parentchild ├── Basic.java ├── Company.java ├── Diagnosis.java ├── Employee.java ├── Exam.java ├── Medical.java └── ParentChildTest.java ├── query ├── MoreLikeThis.java └── TestQuery.java ├── score ├── FunctionScriptScoreTest.java └── UserInfo.java ├── script ├── ScriptImpl7Test.java └── ScriptImplTest.java ├── scroll ├── TestScrollAPIQuery.java └── TestScrollQuery.java ├── searchall └── SearchAllTest.java ├── serial └── CharEscapeUtilTest.java ├── simpleapi └── TestSimpleApi.java ├── sql ├── DocObject.java ├── SQLOrm8Test.java ├── SQLOrmTest.java ├── SQLPagineTest.java └── SQLTest.java ├── stop └── StopTest.java ├── textembedding └── TestTextEmbedding.java ├── thirddslcontainer ├── DocumentCRUD.java ├── DocumentCRUD7.java ├── HighlightSearch.java ├── HighlightSearch7.java ├── ScriptImpl.java ├── ScriptImpl7.java ├── TestThirdDslContainer.java ├── TestThirdDslContainer7.java └── TestThirdDslContainer7WithMysql.java └── xpack └── CleanMonitor.java /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | /target/ 49 | /.classpath 50 | /.project 51 | /.settings/ 52 | /README.md.bak 53 | /common-1.log 54 | /eshelloword-booter.iml 55 | 56 | eshelloword-booter.iml 57 | testdb 58 | /.gradle/ 59 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Bboss is a good elasticsearch Java rest client. It operates and accesses elasticsearch in a way similar to mybatis. 2 | 3 | # BBoss Environmental requirements 4 | 5 | JDK requirement: JDK 1.8+ 6 | 7 | Elasticsearch version requirements: 1.x,2.X,5.X,6. X,+ 8 | 9 | Spring booter 1.x,2.x,+ 10 | #基于bboss es booter demo 的maven工程 11 | 本实例是一个bboss es booter的demo maven工程,可供各种类型项目集成参考 12 | 13 | 14 | # 工程集成说明 15 | ## 快速集成和应用 16 | 17 | 非spring boot项目: 18 | 19 | https://esdoc.bbossgroups.com/#/common-project-with-bboss 20 | 21 | spring boot项目: 22 | 23 | https://esdoc.bbossgroups.com/#/spring-booter-with-bboss 24 | 25 | 详细配置说明参考文档: 26 | 27 | https://esdoc.bbossgroups.com/#/development 28 | 29 | ## demo功能说明: 30 | 31 | ## 2.1 定义实体对象Demo 32 | 33 | ## 2.2 编写测试功能对象-DocumentCRUD.java 34 | 创建dsl配置文件-esmapper/demo.xml 35 | 36 | 删除和创建mapping 37 | 38 | 单文档添加/修改/删除 39 | 40 | 文档批量添加(elasticsearch不是实时flush记录,所以批量添加后如果立即查询可能查询不到刚添加的记录) 41 | 42 | 文档批量修改(elasticsearch不是实时flush记录,所以批量修改后如果立即查询可能查询不到刚修改的效果) 43 | 44 | 文档检索 45 | 46 | 关键词高亮检索 47 | # 运行demo 48 | src/test/java目录下面提供提供很多可以直接运行的的junit测试用例 49 | 50 | 比如运行增删改查: 51 | 52 | elasticsearch 5.x,6.x 53 | 54 | org.bboss.elasticsearchtest.crud.DocumentCRUDTest 55 | 56 | elasticsearch 7.x 57 | 58 | org.bboss.elasticsearchtest.crud.DocumentCRUD7Test 59 | ## 开发交流群 60 | 166471282 61 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 1.8 8 | 1.8 9 | 10 | 11 | org.bboss.eshelloword 12 | elasticsearch-example 13 | 1.0-SNAPSHOT 14 | 15 | 16 | com.bbossgroups.plugins 17 | bboss-datatran-jdbc 18 | 7.3.9 19 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 32 | 33 | 34 | 35 | 36 | 37 | 42 | 43 | 48 | 49 | 50 | junit 51 | junit 52 | 4.13.1 53 | test 54 | 55 | 56 | com.mysql 57 | mysql-connector-j 58 | 8.2.0 59 | test 60 | 61 | 62 | 63 | org.xerial 64 | sqlite-jdbc 65 | 3.42.0.0 66 | test 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /src/main/java/org/bboss/elasticsearchtest/crud/Demo.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.crud;/* 2 | * Copyright 2008 biaoping.yin 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 | 17 | 18 | import com.frameworkset.orm.annotation.ESId; 19 | import com.frameworkset.orm.annotation.ESMatchedQueries; 20 | import org.frameworkset.elasticsearch.entity.ESBaseData; 21 | 22 | import java.time.LocalDateTime; 23 | import java.util.Date; 24 | 25 | /** 26 | * 测试实体,可以从ESBaseData对象继承meta属性,检索时会将文档的一下meta属性设置到对象实例中 27 | */ 28 | public class Demo extends ESBaseData { 29 | private Object dynamicPriceTemplate; 30 | //设定文档标识字段 31 | @ESId(readSet = true,persistent = true) 32 | private Long demoId; 33 | @ESMatchedQueries 34 | private String[] testMatchedQueries; 35 | private String contentbody; 36 | private LocalDateTime localDateTime; 37 | /** 当在mapping定义中指定了日期格式时,则需要指定以下两个注解,例如 38 | * 39 | "agentStarttime": { 40 | "type": "date",###指定多个日期格式 41 | "format":"yyyy-MM-dd HH:mm:ss.SSS||yyyy-MM-dd'T'HH:mm:ss.SSS||yyyy-MM-dd HH:mm:ss||epoch_millis" 42 | } 43 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS") 44 | @Column(dataformat = "yyyy-MM-dd HH:mm:ss.SSS") 45 | */ 46 | 47 | protected Date agentStarttime; 48 | private String applicationName; 49 | private String orderId; 50 | private int contrastStatus; 51 | 52 | public String getName() { 53 | return name; 54 | } 55 | 56 | public void setName(String name) { 57 | this.name = name; 58 | } 59 | 60 | private String name; 61 | 62 | public String getContentbody() { 63 | return contentbody; 64 | } 65 | 66 | public void setContentbody(String contentbody) { 67 | this.contentbody = contentbody; 68 | } 69 | 70 | public Date getAgentStarttime() { 71 | return agentStarttime; 72 | } 73 | 74 | public void setAgentStarttime(Date agentStarttime) { 75 | this.agentStarttime = agentStarttime; 76 | } 77 | 78 | public String getApplicationName() { 79 | return applicationName; 80 | } 81 | 82 | public void setApplicationName(String applicationName) { 83 | this.applicationName = applicationName; 84 | } 85 | 86 | public Long getDemoId() { 87 | return demoId; 88 | } 89 | 90 | public void setDemoId(Long demoId) { 91 | this.demoId = demoId; 92 | } 93 | 94 | public Object getDynamicPriceTemplate() { 95 | return dynamicPriceTemplate; 96 | } 97 | 98 | public void setDynamicPriceTemplate(Object dynamicPriceTemplate) { 99 | this.dynamicPriceTemplate = dynamicPriceTemplate; 100 | } 101 | 102 | public String getOrderId() { 103 | return orderId; 104 | } 105 | 106 | public void setOrderId(String orderId) { 107 | this.orderId = orderId; 108 | } 109 | 110 | public int getContrastStatus() { 111 | return contrastStatus; 112 | } 113 | 114 | public void setContrastStatus(int contrastStatus) { 115 | this.contrastStatus = contrastStatus; 116 | } 117 | 118 | 119 | public String[] getTestMatchedQueries() { 120 | return testMatchedQueries; 121 | } 122 | 123 | public void setTestMatchedQueries(String[] testMatchedQueries) { 124 | this.testMatchedQueries = testMatchedQueries; 125 | } 126 | 127 | public LocalDateTime getLocalDateTime() { 128 | return localDateTime; 129 | } 130 | 131 | public void setLocalDateTime(LocalDateTime localDateTime) { 132 | this.localDateTime = localDateTime; 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /src/main/java/org/bboss/elasticsearchtest/crud/DemoWithES7Index.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.crud;/* 2 | * Copyright 2008 biaoping.yin 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 | 17 | 18 | import com.frameworkset.orm.annotation.ESId; 19 | import com.frameworkset.orm.annotation.ESIndex; 20 | import org.frameworkset.elasticsearch.entity.ESBaseData; 21 | 22 | import java.time.LocalDateTime; 23 | import java.util.Date; 24 | 25 | /** 26 | * 测试实体,可以从ESBaseData对象继承meta属性,检索时会将文档的一下meta属性设置到对象实例中 27 | */ 28 | //@ESIndex(name="demowithesindex-{agentStarttime,yyyy.MM.dd}",type="demowithesindex") 29 | @ESIndex(name="demowithesindex-{dateformat=yyyy.MM.dd}") 30 | public class DemoWithES7Index extends ESBaseData { 31 | private Object dynamicPriceTemplate; 32 | //设定文档标识字段 33 | @ESId(readSet = true,persistent = false) 34 | private Long demoId; 35 | private String contentbody; 36 | 37 | public LocalDateTime getLocalDateTime() { 38 | return localDateTime; 39 | } 40 | 41 | public void setLocalDateTime(LocalDateTime localDateTime) { 42 | this.localDateTime = localDateTime; 43 | } 44 | 45 | /** 当在mapping定义中指定了日期格式时,则需要指定以下两个注解,例如 46 | * 47 | "agentStarttime": { 48 | "type": "date",###指定多个日期格式 49 | "format":"yyyy-MM-dd HH:mm:ss.SSS||yyyy-MM-dd'T'HH:mm:ss.SSS||yyyy-MM-dd HH:mm:ss||epoch_millis" 50 | } 51 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS") 52 | @Column(dataformat = "yyyy-MM-dd HH:mm:ss.SSS") 53 | */ 54 | private LocalDateTime localDateTime; 55 | protected Date agentStarttime; 56 | private String applicationName; 57 | private String orderId; 58 | private int contrastStatus; 59 | 60 | public String getName() { 61 | return name; 62 | } 63 | 64 | public void setName(String name) { 65 | this.name = name; 66 | } 67 | 68 | private String name; 69 | 70 | public String getContentbody() { 71 | return contentbody; 72 | } 73 | 74 | public void setContentbody(String contentbody) { 75 | this.contentbody = contentbody; 76 | } 77 | 78 | public Date getAgentStarttime() { 79 | return agentStarttime; 80 | } 81 | 82 | public void setAgentStarttime(Date agentStarttime) { 83 | this.agentStarttime = agentStarttime; 84 | } 85 | 86 | public String getApplicationName() { 87 | return applicationName; 88 | } 89 | 90 | public void setApplicationName(String applicationName) { 91 | this.applicationName = applicationName; 92 | } 93 | 94 | public Long getDemoId() { 95 | return demoId; 96 | } 97 | 98 | public void setDemoId(Long demoId) { 99 | this.demoId = demoId; 100 | } 101 | 102 | public Object getDynamicPriceTemplate() { 103 | return dynamicPriceTemplate; 104 | } 105 | 106 | public void setDynamicPriceTemplate(Object dynamicPriceTemplate) { 107 | this.dynamicPriceTemplate = dynamicPriceTemplate; 108 | } 109 | 110 | public String getOrderId() { 111 | return orderId; 112 | } 113 | 114 | public void setOrderId(String orderId) { 115 | this.orderId = orderId; 116 | } 117 | 118 | public int getContrastStatus() { 119 | return contrastStatus; 120 | } 121 | 122 | public void setContrastStatus(int contrastStatus) { 123 | this.contrastStatus = contrastStatus; 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /src/main/java/org/bboss/elasticsearchtest/crud/DemoWithES7IndexSimple.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.crud;/* 2 | * Copyright 2008 biaoping.yin 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 | 17 | 18 | import com.frameworkset.orm.annotation.ESId; 19 | import com.frameworkset.orm.annotation.ESIndex; 20 | 21 | import java.util.Date; 22 | 23 | /** 24 | * 测试实体,可以从ESBaseData对象继承meta属性,检索时会将文档的一下meta属性设置到对象实例中 25 | */ 26 | //@ESIndex(name="demowithesindex-{agentStarttime,yyyy.MM.dd}",type="demowithesindex") 27 | @ESIndex(name="demo") 28 | public class DemoWithES7IndexSimple { 29 | private Object dynamicPriceTemplate; 30 | //设定文档标识字段 31 | @ESId(readSet = true,persistent = false) 32 | private Long demoId; 33 | private String contentbody; 34 | /** 当在mapping定义中指定了日期格式时,则需要指定以下两个注解,例如 35 | * 36 | "agentStarttime": { 37 | "type": "date",###指定多个日期格式 38 | "format":"yyyy-MM-dd HH:mm:ss.SSS||yyyy-MM-dd'T'HH:mm:ss.SSS||yyyy-MM-dd HH:mm:ss||epoch_millis" 39 | } 40 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS") 41 | @Column(dataformat = "yyyy-MM-dd HH:mm:ss.SSS") 42 | */ 43 | 44 | protected Date agentStarttime; 45 | private String applicationName; 46 | private String orderId; 47 | private int contrastStatus; 48 | 49 | public String getName() { 50 | return name; 51 | } 52 | 53 | public void setName(String name) { 54 | this.name = name; 55 | } 56 | 57 | private String name; 58 | 59 | public String getContentbody() { 60 | return contentbody; 61 | } 62 | 63 | public void setContentbody(String contentbody) { 64 | this.contentbody = contentbody; 65 | } 66 | 67 | public Date getAgentStarttime() { 68 | return agentStarttime; 69 | } 70 | 71 | public void setAgentStarttime(Date agentStarttime) { 72 | this.agentStarttime = agentStarttime; 73 | } 74 | 75 | public String getApplicationName() { 76 | return applicationName; 77 | } 78 | 79 | public void setApplicationName(String applicationName) { 80 | this.applicationName = applicationName; 81 | } 82 | 83 | public Long getDemoId() { 84 | return demoId; 85 | } 86 | 87 | public void setDemoId(Long demoId) { 88 | this.demoId = demoId; 89 | } 90 | 91 | public Object getDynamicPriceTemplate() { 92 | return dynamicPriceTemplate; 93 | } 94 | 95 | public void setDynamicPriceTemplate(Object dynamicPriceTemplate) { 96 | this.dynamicPriceTemplate = dynamicPriceTemplate; 97 | } 98 | 99 | public String getOrderId() { 100 | return orderId; 101 | } 102 | 103 | public void setOrderId(String orderId) { 104 | this.orderId = orderId; 105 | } 106 | 107 | public int getContrastStatus() { 108 | return contrastStatus; 109 | } 110 | 111 | public void setContrastStatus(int contrastStatus) { 112 | this.contrastStatus = contrastStatus; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/main/java/org/bboss/elasticsearchtest/crud/DemoWithES7IndexUseBatch.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.crud;/* 2 | * Copyright 2008 biaoping.yin 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 | 17 | 18 | import com.frameworkset.orm.annotation.ESId; 19 | import com.frameworkset.orm.annotation.ESIndex; 20 | import org.frameworkset.elasticsearch.entity.ESBaseData; 21 | 22 | import java.time.LocalDateTime; 23 | import java.util.Date; 24 | 25 | /** 26 | * 测试实体,可以从ESBaseData对象继承meta属性,检索时会将文档的一下meta属性设置到对象实例中 27 | * 当ESIndex的name只是用当前时间作为后缀,那么useBatchContextIndexName可以设置为true,提升解析动态索引名称性能,否则保持默认值false 28 | */ 29 | //@ESIndex(name="demowithesindex-{agentStarttime,yyyy.MM.dd}",type="demowithesindex") 30 | @ESIndex(name="demowithesindex-{dateformat=yyyy.MM.dd}",useBatchContextIndexName = true) 31 | public class DemoWithES7IndexUseBatch extends ESBaseData { 32 | private Object dynamicPriceTemplate; 33 | //设定文档标识字段 34 | @ESId(readSet = true,persistent = false) 35 | private Long demoId; 36 | private String contentbody; 37 | /** 当在mapping定义中指定了日期格式时,则需要指定以下两个注解,例如 38 | * 39 | "agentStarttime": { 40 | "type": "date",###指定多个日期格式 41 | "format":"yyyy-MM-dd HH:mm:ss.SSS||yyyy-MM-dd'T'HH:mm:ss.SSS||yyyy-MM-dd HH:mm:ss||epoch_millis" 42 | } 43 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS") 44 | @Column(dataformat = "yyyy-MM-dd HH:mm:ss.SSS") 45 | */ 46 | private LocalDateTime localDateTime; 47 | protected Date agentStarttime; 48 | private String applicationName; 49 | private String orderId; 50 | private int contrastStatus; 51 | 52 | public String getName() { 53 | return name; 54 | } 55 | 56 | public void setName(String name) { 57 | this.name = name; 58 | } 59 | 60 | private String name; 61 | 62 | public String getContentbody() { 63 | return contentbody; 64 | } 65 | 66 | public void setContentbody(String contentbody) { 67 | this.contentbody = contentbody; 68 | } 69 | 70 | public Date getAgentStarttime() { 71 | return agentStarttime; 72 | } 73 | 74 | public void setAgentStarttime(Date agentStarttime) { 75 | this.agentStarttime = agentStarttime; 76 | } 77 | 78 | public String getApplicationName() { 79 | return applicationName; 80 | } 81 | 82 | public void setApplicationName(String applicationName) { 83 | this.applicationName = applicationName; 84 | } 85 | 86 | public Long getDemoId() { 87 | return demoId; 88 | } 89 | 90 | public void setDemoId(Long demoId) { 91 | this.demoId = demoId; 92 | } 93 | 94 | public Object getDynamicPriceTemplate() { 95 | return dynamicPriceTemplate; 96 | } 97 | 98 | public void setDynamicPriceTemplate(Object dynamicPriceTemplate) { 99 | this.dynamicPriceTemplate = dynamicPriceTemplate; 100 | } 101 | 102 | public String getOrderId() { 103 | return orderId; 104 | } 105 | 106 | public void setOrderId(String orderId) { 107 | this.orderId = orderId; 108 | } 109 | 110 | public int getContrastStatus() { 111 | return contrastStatus; 112 | } 113 | 114 | public void setContrastStatus(int contrastStatus) { 115 | this.contrastStatus = contrastStatus; 116 | } 117 | 118 | public LocalDateTime getLocalDateTime() { 119 | return localDateTime; 120 | } 121 | 122 | public void setLocalDateTime(LocalDateTime localDateTime) { 123 | this.localDateTime = localDateTime; 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /src/main/java/org/bboss/elasticsearchtest/crud/DemoWithESIndex.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.crud;/* 2 | * Copyright 2008 biaoping.yin 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 | 17 | 18 | import com.frameworkset.orm.annotation.ESId; 19 | import com.frameworkset.orm.annotation.ESIndex; 20 | import org.frameworkset.elasticsearch.entity.ESBaseData; 21 | 22 | import java.util.Date; 23 | 24 | /** 25 | * 测试实体,可以从ESBaseData对象继承meta属性,检索时会将文档的一下meta属性设置到对象实例中 26 | */ 27 | //@ESIndex(name="demowithesindex-{agentStarttime,yyyy.MM.dd}",type="demowithesindex") 28 | @ESIndex(name="demowithesindex-{dateformat=yyyy.MM.dd}",type="demowithesindex") 29 | public class DemoWithESIndex extends ESBaseData { 30 | private Object dynamicPriceTemplate; 31 | //设定文档标识字段 32 | @ESId(readSet = true,persistent = false) 33 | private Long demoId; 34 | private String contentbody; 35 | /** 当在mapping定义中指定了日期格式时,则需要指定以下两个注解,例如 36 | * 37 | "agentStarttime": { 38 | "type": "date",###指定多个日期格式 39 | "format":"yyyy-MM-dd HH:mm:ss.SSS||yyyy-MM-dd'T'HH:mm:ss.SSS||yyyy-MM-dd HH:mm:ss||epoch_millis" 40 | } 41 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS") 42 | @Column(dataformat = "yyyy-MM-dd HH:mm:ss.SSS") 43 | */ 44 | 45 | protected Date agentStarttime; 46 | private String applicationName; 47 | private String orderId; 48 | private int contrastStatus; 49 | 50 | public String getName() { 51 | return name; 52 | } 53 | 54 | public void setName(String name) { 55 | this.name = name; 56 | } 57 | 58 | private String name; 59 | 60 | public String getContentbody() { 61 | return contentbody; 62 | } 63 | 64 | public void setContentbody(String contentbody) { 65 | this.contentbody = contentbody; 66 | } 67 | 68 | public Date getAgentStarttime() { 69 | return agentStarttime; 70 | } 71 | 72 | public void setAgentStarttime(Date agentStarttime) { 73 | this.agentStarttime = agentStarttime; 74 | } 75 | 76 | public String getApplicationName() { 77 | return applicationName; 78 | } 79 | 80 | public void setApplicationName(String applicationName) { 81 | this.applicationName = applicationName; 82 | } 83 | 84 | public Long getDemoId() { 85 | return demoId; 86 | } 87 | 88 | public void setDemoId(Long demoId) { 89 | this.demoId = demoId; 90 | } 91 | 92 | public Object getDynamicPriceTemplate() { 93 | return dynamicPriceTemplate; 94 | } 95 | 96 | public void setDynamicPriceTemplate(Object dynamicPriceTemplate) { 97 | this.dynamicPriceTemplate = dynamicPriceTemplate; 98 | } 99 | 100 | public String getOrderId() { 101 | return orderId; 102 | } 103 | 104 | public void setOrderId(String orderId) { 105 | this.orderId = orderId; 106 | } 107 | 108 | public int getContrastStatus() { 109 | return contrastStatus; 110 | } 111 | 112 | public void setContrastStatus(int contrastStatus) { 113 | this.contrastStatus = contrastStatus; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/main/java/org/bboss/elasticsearchtest/crud/FieldDemo.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.crud;/* 2 | * Copyright 2008 biaoping.yin 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 | 17 | 18 | import java.time.LocalDateTime; 19 | import java.util.Date; 20 | 21 | /** 22 | * 测试实体,可以从ESBaseData对象继承meta属性,检索时会将文档的一下meta属性设置到对象实例中 23 | */ 24 | public class FieldDemo { 25 | private Object dynamicPriceTemplate; 26 | //设定文档标识字段 27 | private Long demoId; 28 | private String contentbody; 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 | private LocalDateTime localDateTime; 39 | protected Date agentStarttime; 40 | private String applicationName; 41 | private String orderId; 42 | private int contrastStatus; 43 | 44 | public String getName() { 45 | return name; 46 | } 47 | 48 | public void setName(String name) { 49 | this.name = name; 50 | } 51 | 52 | private String name; 53 | 54 | public String getContentbody() { 55 | return contentbody; 56 | } 57 | 58 | public void setContentbody(String contentbody) { 59 | this.contentbody = contentbody; 60 | } 61 | 62 | public Date getAgentStarttime() { 63 | return agentStarttime; 64 | } 65 | 66 | public void setAgentStarttime(Date agentStarttime) { 67 | this.agentStarttime = agentStarttime; 68 | } 69 | 70 | public String getApplicationName() { 71 | return applicationName; 72 | } 73 | 74 | public void setApplicationName(String applicationName) { 75 | this.applicationName = applicationName; 76 | } 77 | 78 | public Long getDemoId() { 79 | return demoId; 80 | } 81 | 82 | public void setDemoId(Long demoId) { 83 | this.demoId = demoId; 84 | } 85 | 86 | public Object getDynamicPriceTemplate() { 87 | return dynamicPriceTemplate; 88 | } 89 | 90 | public void setDynamicPriceTemplate(Object dynamicPriceTemplate) { 91 | this.dynamicPriceTemplate = dynamicPriceTemplate; 92 | } 93 | 94 | public String getOrderId() { 95 | return orderId; 96 | } 97 | 98 | public void setOrderId(String orderId) { 99 | this.orderId = orderId; 100 | } 101 | 102 | public int getContrastStatus() { 103 | return contrastStatus; 104 | } 105 | 106 | public void setContrastStatus(int contrastStatus) { 107 | this.contrastStatus = contrastStatus; 108 | } 109 | 110 | public LocalDateTime getLocalDateTime() { 111 | return localDateTime; 112 | } 113 | 114 | public void setLocalDateTime(LocalDateTime localDateTime) { 115 | this.localDateTime = localDateTime; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/main/java/org/bboss/elasticsearchtest/crud/NewDemo.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.crud; 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 | 18 | import com.frameworkset.orm.annotation.ESId; 19 | import com.frameworkset.orm.annotation.ESMatchedQueries; 20 | 21 | import java.time.LocalDateTime; 22 | import java.util.Date; 23 | 24 | /** 25 | *

Description:

26 | *

27 | *

Copyright (c) 2018

28 | * @Date 2018/7/8 13:41 29 | * @author biaoping.yin 30 | * @version 1.0 31 | */ 32 | public class NewDemo { 33 | private LocalDateTime localDateTime; 34 | @ESId(readSet = true) 35 | private Long demoId; 36 | 37 | public Long getDemoId() { 38 | return demoId; 39 | } 40 | 41 | public void setDemoId(Long demoId) { 42 | this.demoId = demoId; 43 | } 44 | 45 | private Object dynamicPriceTemplate; 46 | 47 | @ESMatchedQueries 48 | private String[] testMatchedQueries; 49 | private String contentbody; 50 | /** 当在mapping定义中指定了日期格式时,则需要指定以下两个注解,例如 51 | * 52 | "agentStarttime": { 53 | "type": "date",###指定多个日期格式 54 | "format":"yyyy-MM-dd HH:mm:ss.SSS||yyyy-MM-dd'T'HH:mm:ss.SSS||yyyy-MM-dd HH:mm:ss||epoch_millis" 55 | } 56 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS") 57 | @Column(dataformat = "yyyy-MM-dd HH:mm:ss.SSS") 58 | */ 59 | 60 | protected Date agentStarttime; 61 | private String applicationName; 62 | private String orderId; 63 | private int contrastStatus; 64 | 65 | public String getName() { 66 | return name; 67 | } 68 | 69 | public void setName(String name) { 70 | this.name = name; 71 | } 72 | 73 | private String name; 74 | 75 | public String getContentbody() { 76 | return contentbody; 77 | } 78 | 79 | public void setContentbody(String contentbody) { 80 | this.contentbody = contentbody; 81 | } 82 | 83 | public Date getAgentStarttime() { 84 | return agentStarttime; 85 | } 86 | 87 | public void setAgentStarttime(Date agentStarttime) { 88 | this.agentStarttime = agentStarttime; 89 | } 90 | 91 | public String getApplicationName() { 92 | return applicationName; 93 | } 94 | 95 | public void setApplicationName(String applicationName) { 96 | this.applicationName = applicationName; 97 | } 98 | 99 | 100 | 101 | public Object getDynamicPriceTemplate() { 102 | return dynamicPriceTemplate; 103 | } 104 | 105 | public void setDynamicPriceTemplate(Object dynamicPriceTemplate) { 106 | this.dynamicPriceTemplate = dynamicPriceTemplate; 107 | } 108 | 109 | public String getOrderId() { 110 | return orderId; 111 | } 112 | 113 | public void setOrderId(String orderId) { 114 | this.orderId = orderId; 115 | } 116 | 117 | public int getContrastStatus() { 118 | return contrastStatus; 119 | } 120 | 121 | public void setContrastStatus(int contrastStatus) { 122 | this.contrastStatus = contrastStatus; 123 | } 124 | 125 | 126 | public String[] getTestMatchedQueries() { 127 | return testMatchedQueries; 128 | } 129 | 130 | public void setTestMatchedQueries(String[] testMatchedQueries) { 131 | this.testMatchedQueries = testMatchedQueries; 132 | } 133 | 134 | public LocalDateTime getLocalDateTime() { 135 | return localDateTime; 136 | } 137 | 138 | public void setLocalDateTime(LocalDateTime localDateTime) { 139 | this.localDateTime = localDateTime; 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /src/main/java/org/bboss/elasticsearchtest/crud/NewDemoPersistent.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.crud; 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 | 18 | import com.frameworkset.orm.annotation.ESId; 19 | import com.frameworkset.orm.annotation.ESMatchedQueries; 20 | 21 | import java.util.Date; 22 | 23 | /** 24 | *

Description:

25 | *

26 | *

Copyright (c) 2018

27 | * @Date 2018/7/8 13:41 28 | * @author biaoping.yin 29 | * @version 1.0 30 | */ 31 | public class NewDemoPersistent { 32 | @ESId(readSet = true,persistent = true) 33 | private Long demoId; 34 | 35 | public Long getDemoId() { 36 | return demoId; 37 | } 38 | 39 | public void setDemoId(Long demoId) { 40 | this.demoId = demoId; 41 | } 42 | 43 | private Object dynamicPriceTemplate; 44 | 45 | @ESMatchedQueries 46 | private String[] testMatchedQueries; 47 | private String contentbody; 48 | /** 当在mapping定义中指定了日期格式时,则需要指定以下两个注解,例如 49 | * 50 | "agentStarttime": { 51 | "type": "date",###指定多个日期格式 52 | "format":"yyyy-MM-dd HH:mm:ss.SSS||yyyy-MM-dd'T'HH:mm:ss.SSS||yyyy-MM-dd HH:mm:ss||epoch_millis" 53 | } 54 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS") 55 | @Column(dataformat = "yyyy-MM-dd HH:mm:ss.SSS") 56 | */ 57 | 58 | protected Date agentStarttime; 59 | private String applicationName; 60 | private String orderId; 61 | private int contrastStatus; 62 | 63 | public String getName() { 64 | return name; 65 | } 66 | 67 | public void setName(String name) { 68 | this.name = name; 69 | } 70 | 71 | private String name; 72 | 73 | public String getContentbody() { 74 | return contentbody; 75 | } 76 | 77 | public void setContentbody(String contentbody) { 78 | this.contentbody = contentbody; 79 | } 80 | 81 | public Date getAgentStarttime() { 82 | return agentStarttime; 83 | } 84 | 85 | public void setAgentStarttime(Date agentStarttime) { 86 | this.agentStarttime = agentStarttime; 87 | } 88 | 89 | public String getApplicationName() { 90 | return applicationName; 91 | } 92 | 93 | public void setApplicationName(String applicationName) { 94 | this.applicationName = applicationName; 95 | } 96 | 97 | 98 | 99 | public Object getDynamicPriceTemplate() { 100 | return dynamicPriceTemplate; 101 | } 102 | 103 | public void setDynamicPriceTemplate(Object dynamicPriceTemplate) { 104 | this.dynamicPriceTemplate = dynamicPriceTemplate; 105 | } 106 | 107 | public String getOrderId() { 108 | return orderId; 109 | } 110 | 111 | public void setOrderId(String orderId) { 112 | this.orderId = orderId; 113 | } 114 | 115 | public int getContrastStatus() { 116 | return contrastStatus; 117 | } 118 | 119 | public void setContrastStatus(int contrastStatus) { 120 | this.contrastStatus = contrastStatus; 121 | } 122 | 123 | 124 | public String[] getTestMatchedQueries() { 125 | return testMatchedQueries; 126 | } 127 | 128 | public void setTestMatchedQueries(String[] testMatchedQueries) { 129 | this.testMatchedQueries = testMatchedQueries; 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /src/main/java/org/bboss/elasticsearchtest/crud/UUIDDemo.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.crud;/* 2 | * Copyright 2008 biaoping.yin 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 | 17 | 18 | import com.frameworkset.orm.annotation.ESMetaId; 19 | 20 | import java.util.Date; 21 | 22 | /** 23 | * 测试实体,可以从ESBaseData对象继承meta属性,检索时会将文档的一下meta属性设置到对象实例中 24 | */ 25 | public class UUIDDemo { 26 | @ESMetaId 27 | private String did; 28 | private Object dynamicPriceTemplate; 29 | //设定文档标识字段 30 | private Long demoId; 31 | private String contentbody; 32 | /** 当在mapping定义中指定了日期格式时,则需要指定以下两个注解,例如 33 | * 34 | "agentStarttime": { 35 | "type": "date",###指定多个日期格式 36 | "format":"yyyy-MM-dd HH:mm:ss.SSS||yyyy-MM-dd'T'HH:mm:ss.SSS||yyyy-MM-dd HH:mm:ss||epoch_millis" 37 | } 38 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS") 39 | @Column(dataformat = "yyyy-MM-dd HH:mm:ss.SSS") 40 | */ 41 | 42 | protected Date agentStarttime; 43 | private String applicationName; 44 | private String orderId; 45 | private int contrastStatus; 46 | 47 | public String getName() { 48 | return name; 49 | } 50 | 51 | public void setName(String name) { 52 | this.name = name; 53 | } 54 | 55 | private String name; 56 | 57 | public String getContentbody() { 58 | return contentbody; 59 | } 60 | 61 | public void setContentbody(String contentbody) { 62 | this.contentbody = contentbody; 63 | } 64 | 65 | public Date getAgentStarttime() { 66 | return agentStarttime; 67 | } 68 | 69 | public void setAgentStarttime(Date agentStarttime) { 70 | this.agentStarttime = agentStarttime; 71 | } 72 | 73 | public String getApplicationName() { 74 | return applicationName; 75 | } 76 | 77 | public void setApplicationName(String applicationName) { 78 | this.applicationName = applicationName; 79 | } 80 | 81 | public Long getDemoId() { 82 | return demoId; 83 | } 84 | 85 | public void setDemoId(Long demoId) { 86 | this.demoId = demoId; 87 | } 88 | 89 | public Object getDynamicPriceTemplate() { 90 | return dynamicPriceTemplate; 91 | } 92 | 93 | public void setDynamicPriceTemplate(Object dynamicPriceTemplate) { 94 | this.dynamicPriceTemplate = dynamicPriceTemplate; 95 | } 96 | 97 | public String getOrderId() { 98 | return orderId; 99 | } 100 | 101 | public void setOrderId(String orderId) { 102 | this.orderId = orderId; 103 | } 104 | 105 | public int getContrastStatus() { 106 | return contrastStatus; 107 | } 108 | 109 | public void setContrastStatus(int contrastStatus) { 110 | this.contrastStatus = contrastStatus; 111 | } 112 | 113 | public String getDid() { 114 | return did; 115 | } 116 | 117 | public void setDid(String did) { 118 | this.did = did; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/main/java/org/bboss/elasticsearchtest/script/DynamicPriceTemplate.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.script;/* 2 | * Copyright 2008 biaoping.yin 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 | 17 | import java.util.List; 18 | 19 | public class DynamicPriceTemplate { 20 | private int goodsId; 21 | private String goodName; 22 | private List rules; 23 | 24 | public int getGoodsId() { 25 | return goodsId; 26 | } 27 | 28 | public void setGoodsId(int goodsId) { 29 | this.goodsId = goodsId; 30 | } 31 | 32 | public List getRules() { 33 | return rules; 34 | } 35 | 36 | public void setRules(List rules) { 37 | this.rules = rules; 38 | } 39 | 40 | public String getGoodName() { 41 | return goodName; 42 | } 43 | 44 | public void setGoodName(String goodName) { 45 | this.goodName = goodName; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/bboss/elasticsearchtest/script/Rule.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.script;/* 2 | * Copyright 2008 biaoping.yin 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 | 17 | public class Rule { 18 | private String ruleId; 19 | private int ruleCount; 20 | 21 | public String getRuleId() { 22 | return ruleId; 23 | } 24 | 25 | public void setRuleId(String ruleId) { 26 | this.ruleId = ruleId; 27 | } 28 | 29 | public int getRuleCount() { 30 | return ruleCount; 31 | } 32 | 33 | public void setRuleCount(int ruleCount) { 34 | this.ruleCount = ruleCount; 35 | } 36 | 37 | public boolean isRuleExist() { 38 | return ruleExist; 39 | } 40 | 41 | public void setRuleExist(boolean ruleExist) { 42 | this.ruleExist = ruleExist; 43 | } 44 | 45 | private boolean ruleExist; 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/bboss/elasticsearchtest/searchafter/DocumentSearchAfter.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.searchafter;/* 2 | * Copyright 2008 biaoping.yin 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 | 17 | import org.apache.commons.collections.map.HashedMap; 18 | import org.bboss.elasticsearchtest.crud.Demo; 19 | import org.bboss.elasticsearchtest.crud.DocumentCRUD; 20 | import org.frameworkset.elasticsearch.ElasticSearchHelper; 21 | import org.frameworkset.elasticsearch.client.ClientInterface; 22 | import org.frameworkset.elasticsearch.entity.ESDatas; 23 | 24 | import java.text.DateFormat; 25 | import java.text.ParseException; 26 | import java.text.SimpleDateFormat; 27 | import java.util.Date; 28 | import java.util.List; 29 | import java.util.Map; 30 | 31 | public class DocumentSearchAfter { 32 | /** 33 | * 创建索引表并导入searchAfter分页测试数据 34 | */ 35 | public void initIndiceAndData(){ 36 | DocumentCRUD documentCRUD = new DocumentCRUD(); 37 | documentCRUD.testCreateIndice(); 38 | documentCRUD.testBulkAddDocuments(); 39 | } 40 | public void doSeachAfter() throws ParseException { 41 | //创建加载配置文件的客户端工具,用来检索文档,单实例多线程安全 42 | ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/searchafter.xml"); 43 | Map params = new HashedMap(); 44 | params.put("pageSize",100); 45 | DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 46 | params.put("startTime",dateFormat.parse("2017-09-02 00:00:00").getTime()); 47 | params.put("endTime",new Date().getTime()); 48 | //执行查询,demo为索引表,_search为检索操作action 49 | ESDatas esDatas = //ESDatas包含当前检索的记录集合,最多1000条记录,由dsl中的size属性指定 50 | clientUtil.searchList("demo_*/_search",//demo为索引表,_search为检索操作action: 51 | // demo/_search 52 | // demo_*/search 53 | // demo_1,demo_2/search 54 | "searchAfterDSL",//esmapper/demo.xml中定义的dsl语句 55 | params,//变量参数 56 | Demo.class);//返回的文档封装对象类型 57 | //获取结果对象列表,最多返回1000条记录 58 | List demos = esDatas.getDatas(); 59 | //获取总记录数 60 | long totalSize = esDatas.getTotalSize(); 61 | 62 | do{ 63 | if(demos != null) 64 | System.out.println("返回当前页记录数:"+demos.size()); 65 | if(demos != null && demos.size() == 100) { //还有数据,则通过searchAfter继续获取下一页数据 66 | String searchAfterId = demos.get(99).getDemoId()+"";//获取最后一条记录的_id值 67 | params.put("searchAfterId", searchAfterId);//设置searchAfterId为分页起点_id值 68 | long demoId = demos.get(99).getDemoId();//获取最后一条记录的demoId值 69 | params.put("demoId", demoId);//设置searchAfterId为分页起点demoId值 70 | esDatas = //ESDatas包含当前检索的记录集合,最多1000条记录,由dsl中的size属性指定 71 | clientUtil.searchList("demo/_search",//demo为索引表,_search为检索操作action 72 | "searchAfterDSL",//esmapper/demo.xml中定义的dsl语句 73 | params,//变量参数 74 | Demo.class);//返回的文档封装对象类型 75 | 76 | demos = esDatas.getDatas(); 77 | 78 | } 79 | else{//如果是最后一页,没有数据返回或者获取的记录条数少于100结束分页操作 80 | break; 81 | } 82 | }while(true); 83 | System.out.println("总记录数:"+totalSize); 84 | 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/org/bboss/eshelloword/Helloworld.java: -------------------------------------------------------------------------------- 1 | package org.bboss.eshelloword;/* 2 | * Copyright 2008 biaoping.yin 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 | 17 | import org.frameworkset.elasticsearch.ElasticSearchHelper; 18 | import org.frameworkset.elasticsearch.client.ClientInterface; 19 | import org.frameworkset.elasticsearch.entity.ESDatas; 20 | import org.frameworkset.spi.BaseApplicationContext; 21 | 22 | import java.util.Map; 23 | 24 | public class Helloworld { 25 | public static void main(String[] args){ 26 | 27 | //创建es客户端工具,验证环境 28 | // ClientInterface clientUtil = ElasticSearchHelper.getRestClientUtil("logs"); 29 | ClientInterface clientUtil = ElasticSearchHelper.getRestClientUtil(); 30 | //验证环境,获取es状态 31 | // String response = clientUtil.executeHttp("_cluster/state?pretty",ClientInterface.HTTP_GET); 32 | 33 | //判断索引类型是否存在,false表示不存在,正常返回true表示存在 34 | boolean exist = clientUtil.existIndiceType("twitter","tweet"); 35 | 36 | exist = clientUtil.existIndiceType("demo","demo"); 37 | 38 | //判读索引是否存在,false表示不存在,正常返回true表示存在 39 | exist = clientUtil.existIndice("twitter"); 40 | 41 | exist = clientUtil.existIndice("agentinfo"); 42 | 43 | exist = clientUtil.existIndice("demo"); 44 | if(exist) { 45 | long count = clientUtil.countAll("demo"); 46 | System.out.println("count:"+count); 47 | ESDatas esDatas = clientUtil.searchAll("demo", Map.class); 48 | clientUtil.searchAllParallel("demo", Map.class,2); 49 | } 50 | 51 | BaseApplicationContext.shutdown(); 52 | // long count = clientUtil.countAll("agentinfo"); 53 | // System.out.println(response); 54 | // Map state = clientUtil.executeHttp("_cluster/state",ClientInterface.HTTP_GET, 55 | // new ESMapResponseHandler());//返回map结构 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/bboss/eshelloword/MultiESBooter.java: -------------------------------------------------------------------------------- 1 | package org.bboss.eshelloword;/* 2 | * Copyright 2008 biaoping.yin 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 | 17 | import org.frameworkset.elasticsearch.ElasticSearchHelper; 18 | import org.frameworkset.elasticsearch.boot.ElasticSearchBoot; 19 | import org.frameworkset.elasticsearch.client.ClientInterface; 20 | import org.frameworkset.spi.BaseApplicationContext; 21 | 22 | public class MultiESBooter { 23 | public static void main(String[] args){ 24 | 25 | /** 26 | * boot操作必须在所有的ClientInterface组件创建之前调用 27 | * 按照默认的配置文件初始化elasticsearch客户端工具 28 | * conf/elasticsearch.properties,application.properties,config/application.properties 29 | */ 30 | //ElasticSearchBoot.boot(); 31 | 32 | /** 33 | * boot操作必须在所有的ClientInterface组件创建之前调用 34 | * 根据指定的配置文件初始化elasticsearch客户端工具 35 | * @param configFile 指定1到多个多个ElasticSearch属性配置文件,对应的路径格式为(多个用逗号分隔),例如: 36 | * conf/elasticsearch.properties,application.properties,config/application.properties 37 | * 上述的文件都是在classpath下面即可,如果需要指定绝对路径,格式为: 38 | * file:d:/conf/elasticsearch.properties,file:d:/application.properties,config/application.properties 39 | * 40 | * 说明:带file:前缀表示后面的路径为绝对路径 41 | */ 42 | ElasticSearchBoot.boot("application.properties.multicluster"); 43 | 44 | 45 | //ElasticSearchBoot.boot("file:/xxx/xxx/application.properties"); 46 | //创建es客户端工具,验证环境 47 | 48 | ClientInterface configClientUtil = ElasticSearchHelper.getConfigRestClientUtil("logs","esmapper/demo.xml"); 49 | ClientInterface defaultClientUtil = ElasticSearchHelper.getRestClientUtil(); 50 | //验证环境,获取es状态 51 | // String response = clientUtil.executeHttp("_cluster/state?pretty",ClientInterface.HTTP_GET); 52 | ClientInterface clientUtil = ElasticSearchHelper.getRestClientUtil("logs"); 53 | //判断索引类型是否存在,抛出异常表示不存在,正常返回表示存在 54 | boolean exist = configClientUtil.existIndiceType("twitter","tweet"); 55 | System.out.println("twitter,tweet exist:"+exist); 56 | //判读索引是否存在,抛出异常表示不存在,正常返回表示存在 57 | exist = configClientUtil.existIndice("twitter"); 58 | System.out.println("twitter exist:"+exist); 59 | exist = configClientUtil.existIndice("agentinfo"); 60 | System.out.println("agentinfo exist:"+exist); 61 | 62 | defaultClientUtil.existIndice("sss"); 63 | BaseApplicationContext.shutdown(); 64 | // System.out.println(response); 65 | // Map state = clientUtil.executeHttp("_cluster/state",ClientInterface.HTTP_GET, 66 | // new ESMapResponseHandler());//返回map结构 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/resources/application.basicauth.properties: -------------------------------------------------------------------------------- 1 | 2 | ##default集群配配置 3 | # x-pack或者searchguard安全认证和口令配置 4 | elasticUser=elastic 5 | elasticPassword=changeme 6 | 7 | #集群地址配置 8 | #elasticsearch.rest.hostNames=10.180.211.27:9280,10.180.211.27:9281,10.180.211.27:9282 9 | #Proxy Node 10 | #elasticsearch.rest.hostNames=192.168.137.1:9206,192.168.137.1:9207 11 | #elasticsearch.rest.hostNames=es.iisc.com:9200 12 | #elasticsearch.rest.hostNames=localhost:9200 13 | elasticsearch.rest.hostNames=192.168.137.1:9200 14 | #如果开启了https协议,则需要在elasticsearch地址中添加https://协议头 15 | #elasticsearch.rest.hostNames=https://10.180.211.27:9280,https://10.180.211.27:9281,https://10.180.211.27:9282 16 | elasticsearch.dateFormat=yyyy.MM.dd 17 | #在控制台输出脚本调试开关showTemplate,false关闭,true打开,同时log4j至少是info级别 18 | elasticsearch.showTemplate=true 19 | #elasticsearch.logDslCallback=org.frameworkset.elasticsearch.client.LoggerDslCallback 20 | #elasticsearch.slowDslThreshold = 10000 21 | #elasticsearch.slowDslCallback=org.bboss.elasticsearchtest.crud.TestSlowDslCallback 22 | #集群节点自动发现开关 23 | elasticsearch.discoverHost=false 24 | elasticsearch.useHttps=false 25 | 26 | #设置slice scroll查询对应的线程数和等待队列数 27 | elasticsearch.sliceScrollThreadCount=100 28 | elasticsearch.sliceScrollThreadQueue=100 29 | elasticsearch.sliceScrollBlockedWaitTimeout=0 30 | 31 | #设置scroll查询对应的线程数和等待队列数 32 | elasticsearch.scrollThreadCount=50 33 | elasticsearch.scrollThreadQueue=50 34 | elasticsearch.scrollBlockedWaitTimeout=0 35 | elasticsearch.includeTypeName = false 36 | ## 没有可用节点时,从失败节点中选择一个 37 | elasticsearch.failAllContinue = true 38 | 39 | ##default连接池配置 40 | http.timeoutConnection = 50000 41 | http.timeoutSocket = 50000 42 | http.connectionRequestTimeout=50000 43 | http.retryTime = -1 44 | http.retryInterval = 3000 45 | http.automaticRetriesDisabled=false 46 | #* 自定义重试控制接口,必须实现接口方法 47 | #* public interface CustomHttpRequestRetryHandler { 48 | #* public boolean retryRequest(IOException exception, int executionCount, HttpContext context,ClientConfiguration configuration); 49 | #* } 50 | #* 方法返回true,进行重试,false不重试 51 | # http.customHttpRequestRetryHandler=org.frameworkset.spi.remote.http.DefaultHttpRequestRetryHandler 52 | #http.customHttpRequestRetryHandler=org.frameworkset.spi.remote.http.ConnectionResetHttpRequestRetryHandler 53 | http.maxLineLength = -1 54 | http.maxHeaderCount = 200 55 | http.maxTotal = 400 56 | http.defaultMaxPerRoute = 200 57 | http.soReuseAddress = false 58 | http.soKeepAlive = false 59 | http.timeToLive = 3600000 60 | http.keepAlive = 3600000 61 | #基于apiKeyId和apiKeySecret认证配置(主要用于Elasticsearch认证) 62 | #http.apiKeyId = aaaa 63 | #http.apiKeySecret = bbbbbb 64 | 65 | # Using the keystore- and truststore file 66 | ## http.keystore = D:/workspace/bbossesdemo/eshelloword-booter/src/main/resources/sgadmin-keystore.jks 67 | ## http.keyPassword = 7240a0366eb6a764103e 68 | ## http.truststore = D:/workspace/bbossesdemo/eshelloword-booter/src/main/resources/truststore.jks 69 | ## http.trustPassword = 6aa4bd79096852203a5b 70 | 71 | # Using PEM certificates 72 | ## http.pemCert = D:/workspace/bbossesdemo/eshelloword-booter/src/main/resources/sgadmin.crtfull.pem 73 | ## http.pemtrustedCA = D:/workspace/bbossesdemo/eshelloword-booter/src/main/resources/chain-ca.pem 74 | ## http.pemKey = D:/workspace/bbossesdemo/eshelloword-booter/src/main/resources/sgadmin.key.pem 75 | ## http.pemkeyPassword = 7240a0366eb6a764103e 76 | 77 | # ssl 主机名称校验,是否采用default配置, 78 | # 如果指定为default,就采用DefaultHostnameVerifier,否则采用 SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER 79 | http.hostnameVerifier = 80 | # 驱逐http连接池中过期的http连接 81 | http.evictExpiredConnections=true 82 | #每隔多少毫秒校验空闲connection,自动释放无效链接 83 | # -1 或者0不检查 84 | http.validateAfterInactivity=3000 85 | # 每次获取connection时校验连接,true,校验,false不校验,有性能开销 86 | 87 | # 默认值false 88 | http.staleConnectionCheckEnabled=false 89 | 90 | http.backoffAuth=true 91 | 92 | # dsl配置文件热加载扫描时间间隔,毫秒为单位,默认5秒扫描一次,<= 0时关闭扫描机制 93 | dslfile.refreshInterval = 5000 94 | # 指定存放dsl配置文件的地址 95 | #dslfile.dslMappingDir=D:/workspace/bbossesdemo/eshelloword-booter/src/main/resources/ 96 | 97 | # 演示数据库数据导入elasticsearch源配置 98 | db.name = test 99 | db.user = root 100 | db.password = 123456 101 | db.driver = com.mysql.cj.jdbc.Driver 102 | db.url = jdbc:mysql://localhost:3306/bboss?useCursorFetch=true 103 | db.usePool = true 104 | db.validateSQL = select 1 105 | db.jdbcFetchSize = 10000 106 | db.showsql = true -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | ##default集群配配置 3 | # x-pack或者searchguard安全认证和口令配置 4 | elasticUser=elastic 5 | elasticPassword=changeme 6 | 7 | #集群地址配置 8 | #elasticsearch.rest.hostNames=10.180.211.27:9280,10.180.211.27:9281,10.180.211.27:9282 9 | #Proxy Node 10 | #elasticsearch.rest.hostNames=192.168.137.1:9206,192.168.137.1:9207 11 | #elasticsearch.rest.hostNames=es.iisc.com:9200 12 | #elasticsearch.rest.hostNames=localhost:9200 13 | elasticsearch.rest.hostNames=192.168.137.1:9200 14 | #如果开启了https协议,则需要在elasticsearch地址中添加https://协议头 15 | #elasticsearch.rest.hostNames=https://10.180.211.27:9280,https://10.180.211.27:9281,https://10.180.211.27:9282 16 | elasticsearch.dateFormat=yyyy.MM.dd 17 | #在控制台输出脚本调试开关showTemplate,false关闭,true打开,同时log4j至少是info级别 18 | elasticsearch.showTemplate=true 19 | #elasticsearch.logDslCallback=org.frameworkset.elasticsearch.client.LoggerDslCallback 20 | #elasticsearch.slowDslThreshold = 10000 21 | #elasticsearch.slowDslCallback=org.bboss.elasticsearchtest.crud.TestSlowDslCallback 22 | #集群节点自动发现开关 23 | elasticsearch.discoverHost=true 24 | elasticsearch.useHttps=false 25 | 26 | #设置slice scroll查询对应的线程数和等待队列数 27 | elasticsearch.sliceScrollThreadCount=100 28 | elasticsearch.sliceScrollThreadQueue=100 29 | elasticsearch.sliceScrollBlockedWaitTimeout=0 30 | 31 | #设置scroll查询对应的线程数和等待队列数 32 | elasticsearch.scrollThreadCount=50 33 | elasticsearch.scrollThreadQueue=50 34 | elasticsearch.scrollBlockedWaitTimeout=0 35 | elasticsearch.includeTypeName = false 36 | ## 没有可用节点时,从失败节点中选择一个 37 | elasticsearch.failAllContinue = true 38 | 39 | ##default连接池配置 40 | http.timeoutConnection = 50000 41 | http.timeoutSocket = 50000 42 | http.connectionRequestTimeout=50000 43 | http.retryTime = -1 44 | http.retryInterval = 3000 45 | http.automaticRetriesDisabled=false 46 | #* 自定义重试控制接口,必须实现接口方法 47 | #* public interface CustomHttpRequestRetryHandler { 48 | #* public boolean retryRequest(IOException exception, int executionCount, HttpContext context,ClientConfiguration configuration); 49 | #* } 50 | #* 方法返回true,进行重试,false不重试 51 | # http.customHttpRequestRetryHandler=org.frameworkset.spi.remote.http.DefaultHttpRequestRetryHandler 52 | #http.customHttpRequestRetryHandler=org.frameworkset.spi.remote.http.ConnectionResetHttpRequestRetryHandler 53 | http.maxLineLength = -1 54 | http.maxHeaderCount = 200 55 | http.maxTotal = 400 56 | http.defaultMaxPerRoute = 200 57 | http.soReuseAddress = false 58 | http.soKeepAlive = false 59 | http.timeToLive = 3600000 60 | http.keepAlive = 3600000 61 | #基于apiKeyId和apiKeySecret认证配置(主要用于Elasticsearch认证) 62 | #http.apiKeyId = aaaa 63 | #http.apiKeySecret = bbbbbb 64 | 65 | # Using the keystore- and truststore file 66 | ## http.keystore = D:/workspace/bbossesdemo/eshelloword-booter/src/main/resources/sgadmin-keystore.jks 67 | ## http.keyPassword = 7240a0366eb6a764103e 68 | ## http.truststore = D:/workspace/bbossesdemo/eshelloword-booter/src/main/resources/truststore.jks 69 | ## http.trustPassword = 6aa4bd79096852203a5b 70 | 71 | # Using PEM certificates 72 | ## http.pemCert = D:/workspace/bbossesdemo/eshelloword-booter/src/main/resources/sgadmin.crtfull.pem 73 | ## http.pemtrustedCA = D:/workspace/bbossesdemo/eshelloword-booter/src/main/resources/chain-ca.pem 74 | ## http.pemKey = D:/workspace/bbossesdemo/eshelloword-booter/src/main/resources/sgadmin.key.pem 75 | ## http.pemkeyPassword = 7240a0366eb6a764103e 76 | 77 | # ssl 主机名称校验,是否采用default配置, 78 | # 如果指定为default,就采用DefaultHostnameVerifier,否则采用 SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER 79 | http.hostnameVerifier = 80 | # 驱逐http连接池中过期的http连接 81 | http.evictExpiredConnections=true 82 | #每隔多少毫秒校验空闲connection,自动释放无效链接 83 | # -1 或者0不检查 84 | http.validateAfterInactivity=3000 85 | # 每次获取connection时校验连接,true,校验,false不校验,有性能开销 86 | 87 | # 默认值false 88 | http.staleConnectionCheckEnabled=false 89 | 90 | http.backoffAuth=true 91 | 92 | # dsl配置文件热加载扫描时间间隔,毫秒为单位,默认5秒扫描一次,<= 0时关闭扫描机制 93 | dslfile.refreshInterval = 5000 94 | # 指定存放dsl配置文件的地址 95 | #dslfile.dslMappingDir=D:/workspace/bbossesdemo/eshelloword-booter/src/main/resources/ 96 | 97 | # 演示数据库数据导入elasticsearch源配置 98 | db.name = test 99 | db.user = root 100 | db.password = 123456 101 | db.driver = com.mysql.cj.jdbc.Driver 102 | db.url = jdbc:mysql://localhost:3306/bboss?useCursorFetch=true 103 | db.usePool = true 104 | db.validateSQL = select 1 105 | db.jdbcFetchSize = 10000 106 | db.showsql = true -------------------------------------------------------------------------------- /src/main/resources/application.properties.example: -------------------------------------------------------------------------------- 1 | 2 | ##default集群配配置 3 | # x-pack或者searchguard安全认证和口令配置 4 | elasticUser=elastic 5 | elasticPassword=changeme 6 | 7 | #集群地址配置 8 | #elasticsearch.rest.hostNames=10.180.211.27:9280,10.180.211.27:9281,10.180.211.27:9282 9 | #Proxy Node 10 | #elasticsearch.rest.hostNames=192.168.137.1:9206,192.168.137.1:9207 11 | #elasticsearch.rest.hostNames=192.168.137.1:9200 12 | elasticsearch.rest.hostNames=localhost:9201 13 | #如果开启了https协议,则需要在elasticsearch地址中添加https://协议头 14 | #elasticsearch.rest.hostNames=https://10.180.211.27:9280,https://10.180.211.27:9281,https://10.180.211.27:9282 15 | elasticsearch.dateFormat=yyyy.MM.dd 16 | elasticsearch.timeZone=Asia/Shanghai 17 | #在控制台输出脚本调试开关showTemplate,false关闭,true打开,同时log4j至少是info级别 18 | elasticsearch.showTemplate=false 19 | #集群节点自动发现开关 20 | elasticsearch.discoverHost=true 21 | elasticsearch.useHttps=false 22 | 23 | #设置slice scroll查询对应的线程数和等待队列数 24 | elasticsearch.sliceScrollThreadCount=100 25 | elasticsearch.sliceScrollThreadQueue=100 26 | elasticsearch.sliceScrollBlockedWaitTimeout=0 27 | 28 | #设置scroll查询对应的线程数和等待队列数 29 | elasticsearch.scrollThreadCount=50 30 | elasticsearch.scrollThreadQueue=50 31 | elasticsearch.scrollBlockedWaitTimeout=0 32 | elasticsearch.includeTypeName = false 33 | #elasticsearch.slowDslThreshold = 1000 34 | #elasticsearch.slowDslCallback=org.bboss.elasticsearchtest.crud.TestSlowDslCallback 35 | ##default连接池配置 36 | http.timeoutConnection = 5000 37 | http.timeoutSocket = 5000 38 | http.connectionRequestTimeout=5000 39 | http.retryTime = -1 40 | http.retryInterval = 3000 41 | http.automaticRetriesDisabled=false 42 | #* 自定义重试控制接口,必须实现接口方法 43 | #* public interface CustomHttpRequestRetryHandler { 44 | #* public boolean retryRequest(IOException exception, int executionCount, HttpContext context,ClientConfiguration configuration); 45 | #* } 46 | #* 方法返回true,进行重试,false不重试 47 | # http.customHttpRequestRetryHandler=org.frameworkset.spi.remote.http.DefaultHttpRequestRetryHandler 48 | #http.customHttpRequestRetryHandler=org.frameworkset.spi.remote.http.ConnectionResetHttpRequestRetryHandler 49 | http.maxLineLength = -1 50 | http.maxHeaderCount = 200 51 | http.maxTotal = 400 52 | http.defaultMaxPerRoute = 200 53 | http.soReuseAddress = false 54 | http.soKeepAlive = false 55 | http.timeToLive = 3600000 56 | http.keepAlive = 3600000 57 | # Using the keystore- and truststore file 58 | ## http.keystore = D:/workspace/bbossesdemo/eshelloword-booter/src/main/resources/sgadmin-keystore.jks 59 | ## http.keyPassword = 7240a0366eb6a764103e 60 | ## http.truststore = D:/workspace/bbossesdemo/eshelloword-booter/src/main/resources/truststore.jks 61 | ## http.trustPassword = 6aa4bd79096852203a5b 62 | 63 | # Using PEM certificates 64 | ## http.pemCert = D:/workspace/bbossesdemo/eshelloword-booter/src/main/resources/sgadmin.crtfull.pem 65 | ## http.pemtrustedCA = D:/workspace/bbossesdemo/eshelloword-booter/src/main/resources/chain-ca.pem 66 | ## http.pemKey = D:/workspace/bbossesdemo/eshelloword-booter/src/main/resources/sgadmin.key.pem 67 | ## http.pemkeyPassword = 7240a0366eb6a764103e 68 | 69 | # ssl 主机名称校验,是否采用default配置, 70 | # 如果指定为default,就采用DefaultHostnameVerifier,否则采用 SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER 71 | http.hostnameVerifier = 72 | # 驱逐http连接池中过期的http连接 73 | http.evictExpiredConnections=true 74 | #每隔多少毫秒校验空闲connection,自动释放无效链接 75 | # -1 或者0不检查 76 | http.validateAfterInactivity=3000 77 | # 每次获取connection时校验连接,true,校验,false不校验,有性能开销 78 | 79 | # 默认值false 80 | http.staleConnectionCheckEnabled=false 81 | 82 | http.backoffAuth=true 83 | 84 | # dsl配置文件热加载扫描时间间隔,毫秒为单位,默认5秒扫描一次,<= 0时关闭扫描机制 85 | dslfile.refreshInterval = 5000 86 | # 指定存放dsl配置文件的地址 87 | #dslfile.dslMappingDir=D:/workspace/bbossesdemo/eshelloword-booter/src/main/resources/ 88 | 89 | # 演示数据库数据导入elasticsearch源配置 90 | db.name = test 91 | db.user = root 92 | db.password = 123456 93 | db.driver = com.mysql.jdbc.Driver 94 | db.url = jdbc:mysql://localhost:3306/bboss?useCursorFetch=true 95 | db.usePool = true 96 | db.validateSQL = select 1 97 | db.jdbcFetchSize = 10000 98 | db.showsql = true -------------------------------------------------------------------------------- /src/main/resources/dbbulktest.xml: -------------------------------------------------------------------------------- 1 | 2 | 28 | 29 | 30 | 31 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/main/resources/esmapper/badquery.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 33 | 34 | 49 | 50 | 51 | 55 | 56 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /src/main/resources/esmapper/byquery.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 31 | 32 | 33 | 34 | 57 | 58 | -------------------------------------------------------------------------------- /src/main/resources/esmapper/cluster.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 20 | 21 | 25 | 26 | 36 | 37 | 38 | 42 | 43 | 66 | 67 | 68 | 74 | 75 | 112 | 113 | -------------------------------------------------------------------------------- /src/main/resources/esmapper/demo233.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 33 | 34 | 35 | 45 | 46 | 69 | 70 | 71 | 81 | 82 | 0) 90 | #foreach($applicationName in $applicationNames) 91 | #if($foreach.index > 0),#end "$applicationName" 92 | #end 93 | #end 94 | ] 95 | } 96 | }, 97 | { ## 时间范围检索,返回对应时间范围内的记录,接受long型的值 98 | "range": { 99 | "agentStarttime": { 100 | "gte": #[startTime],##统计开始时间 101 | "lt": #[endTime] ##统计截止时间 102 | } 103 | } 104 | } 105 | ] 106 | } 107 | }, 108 | ## 最多返回1000条记录 109 | "size":1000 110 | }]]> 111 | 112 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /src/main/resources/esmapper/dsl.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 42 | 43 | 44 | 45 | 82 | 83 | -------------------------------------------------------------------------------- /src/main/resources/esmapper/dslcacheexample.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 41 | 42 | 43 | 44 | 64 | 65 | -------------------------------------------------------------------------------- /src/main/resources/esmapper/license.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | -------------------------------------------------------------------------------- /src/main/resources/esmapper/matchPhrasePrefixQuery.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/main/resources/esmapper/morelikethis.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/main/resources/esmapper/orderQuery.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 23 | 24 | -------------------------------------------------------------------------------- /src/main/resources/esmapper/outpianduanref.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 41 | 42 | 43 | 47 | 48 | 49 | 50 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/main/resources/esmapper/pianduan.xml: -------------------------------------------------------------------------------- 1 | 2 | 35 | -------------------------------------------------------------------------------- /src/main/resources/esmapper/score.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 23 | 24 | 28 | 29 | 39 | 40 | 41 | 45 | 46 | 69 | 70 | 71 | 77 | 78 | 115 | 116 | -------------------------------------------------------------------------------- /src/main/resources/esmapper/scroll.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 15 | 16 | 19 | 20 | 33 | 34 | -------------------------------------------------------------------------------- /src/main/resources/esmapper/searchafter.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 35 | 36 | -------------------------------------------------------------------------------- /src/main/resources/esmapper/sql.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 12 | 13 | 14 | 17 | 18 | 23 | 24 | 39 | 40 | 41 | 42 | 47 | 48 | 58 | 59 | 60 | 65 | 66 | 76 | 77 | 82 | 83 | 97 | 98 | 99 | 100 | 101 | 104 | 105 | 106 | 107 | 108 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /src/main/resources/esmapper/testagg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 43 | 44 | 45 | 46 | 86 | 87 | -------------------------------------------------------------------------------- /src/main/resources/esmapper/textembedding.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 22 | 23 | 24 | 25 | 37 | 38 | 39 | 40 | 41 | 42 | 52 | 53 | 54 | 55 | 66 | 67 | 68 | 69 | 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/main/resources/searchguard/certs/client-certificates.readme: -------------------------------------------------------------------------------- 1 | Client certificates are used to authenticate REST clients against your authentication backend. 2 | Thus, the users represented by the client certificates must be also present in your authentication backend. 3 | 4 | See http://docs.search-guard.com/latest/client-certificate-auth for more on this topic. 5 | 6 | 7 | CN=spock.example.com,OU=Ops,O=Example Com\, Inc.,DC=example,DC=com Password: VC16h787hOrW 8 | CN=kirk.example.com,OU=Ops,O=Example Com\, Inc.,DC=example,DC=com Password: BG2dRCZmyo5Y 9 | -------------------------------------------------------------------------------- /src/main/resources/searchguard/certs/kirk-keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bbossgroups/elasticsearch-example/1113e1fafcc39d642102873dce4a7ea3943a8f92/src/main/resources/searchguard/certs/kirk-keystore.jks -------------------------------------------------------------------------------- /src/main/resources/searchguard/certs/kirk.key: -------------------------------------------------------------------------------- 1 | -----BEGIN ENCRYPTED PRIVATE KEY----- 2 | MIIE9jAoBgoqhkiG9w0BDAEDMBoEFCKO7Mzgif4ZPoRO8F1a6E0cxuwXAgIIAASC 3 | BMiGz9Kd4KMxxmTKlF28ggeOn1zp1JfqD3oDF6WdLaQZLBvOzL3znGBeGsG0lLNI 4 | T1MlRLv17JTrMQXnKuUYriiDALH3OJm0pXxiVqi1hwfT0mhgGFDCCy9A6lY0LJIP 5 | 4TiXEoKWukJDZPOZqLG/x1M+BVVOYxrEpB/KaoWjSGNpqS5AJiGRG+p2r5U3wxpm 6 | 3Y1ZGqzb9E2CXGSc3KGMZ6kRhwAtvfQD83B3CgOLU4iodlBGeTlmKAOmx0rFiGDp 7 | EEM9Z+GGcVa4xgrBy205I798IR6EzN4OkakmGQnGIv1xFB7gmxpVPb1uiQzZqJrU 8 | qXt2bCyLmjSUqf8doQ+kEl7Fjgo0Pr7gy1As3lxU4y1tYShofvppWG0lZzjJ4NSf 9 | 4PSQdxO3zkOypcCBLSbe1JHwR8cc7/mo6I630+sdGnaDQdDPWXCPKUVi1XzMIkLy 10 | qTWnZgWeMDId5+zMj9YZkdRcJNeALkXzgog8MryCbCXgLX/7T2ybMmhYEctzJ4x1 11 | AiCcR6YIvJ33HBT0PQdE0a/NuUwMGA392EBsRNVp5dJmAJLEChI+psA3/w5v49IJ 12 | C48zu+/7MUBGE2NdcnqPXPlq1FVMfdDazOYUMzw/4/S2ec49LPEk+UunFtjO7Ec9 13 | AM6lwP2Sj3YIl04NTai4+SV6c4NoZ+nZLCi07wtyBdo5Xk+BqGn/Sn4J5bCsv7Jp 14 | 2S9baFhgC26WUblkXMPZWe7kWP8yo7uFauVS2Hg3wWTTn0I8lcve2GzuGhrjOQMi 15 | gl7173NNT2WAdFWfpm2D5ftsdOQw0V9f6V+B3kp672QvmkF2rh/I8PtGh0QxzE9o 16 | ol16ZaMuFCoIxP015ni5XJcrFKuLwvNN+tjq8HltaQ0Ybd32hY76X4hLi61CyIm9 17 | Ensdhd6wWcQfRG6jFqjZ+mTS2sFgqMwpesoc2QWdT7oEzuqNha7WJroKGXd4Kufr 18 | epIqU0kTXe17UZ9jBgVekxy5dEH9LggjAB1RHRSym75Cxf164qZrlUSz/q/S4N5j 19 | ILWVpVRRz7ekuldAPcLi8sjcsKAredwxyAYQF2dcBOVIE6Iaw6BPrYtXggjxEuEU 20 | ykr4fTHMziFmuVAXBRuglHuXT7tP3+AmcLe0lgnuDIQSNN29zp81G6Qf5MPbo4lN 21 | eugpY7eeKFd61cXz1JF8LUmtrKqNv21yPwDTe6J/G/KeQy/EILiqFBRPYpz3mUX0 22 | hJIzWK7Y9rwETd9go3JwNr6kbaW2YquFbMXnpraFFs5iCvfUlaPitsGq423V/N8X 23 | E/4QifOvd7smSrSbzLuh6mLC3wbDKv98zkXHVkj4pljKNkd+whYUpIBjY04bfTXZ 24 | 0zJx1fuZDLsM7WD7NFkQcM/N1AbuTlcEgI3yIitHfIKwPxzFcy8p7LwDA6JawgIF 25 | WfgKXC4bfqXFB/BUUCwwDk3LSfeC89GuN6AvtKgktY//9efmW+RcA67BBalQXPH0 26 | Vf+ALmnYMGNhhsOWYEJiCxNMw9KOzD+ttHQ+cWYWNk8QLsM2otJ/mpzwFLBdAsK+ 27 | +f/MKjMgAxwUCu0IuO0YbA9Y4KnL3Pl5HmBEQM7BKoKydYFA7ENLDw9SkXY5JkQb 28 | Tf0YzfzhOB62uS36uANKMbuge37R0wTWieY= 29 | -----END ENCRYPTED PRIVATE KEY----- 30 | -------------------------------------------------------------------------------- /src/main/resources/searchguard/certs/kirk.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIEYzCCA0ugAwIBAgIGAXJzB76HMA0GCSqGSIb3DQEBCwUAMHUxEzARBgoJkiaJ 3 | k/IsZAEZFgNjb20xFzAVBgoJkiaJk/IsZAEZFgdleGFtcGxlMRowGAYDVQQKDBFF 4 | eGFtcGxlIENvbSwgSW5jLjELMAkGA1UECwwCQ0ExHDAaBgNVBAMME3Jvb3QuY2Eu 5 | ZXhhbXBsZS5jb20wHhcNMjAwNjAyMDMxNzA3WhcNMzAwNTMxMDMxNzA3WjBzMRMw 6 | EQYKCZImiZPyLGQBGRYDY29tMRcwFQYKCZImiZPyLGQBGRYHZXhhbXBsZTEaMBgG 7 | A1UECgwRRXhhbXBsZSBDb20sIEluYy4xDDAKBgNVBAsMA09wczEZMBcGA1UEAwwQ 8 | a2lyay5leGFtcGxlLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB 9 | ALI7yemYR4E8O8eDluw/BQf3hJFpHq2QzoEYPhR72WjIraxfPocO25O1OqzUhPfz 10 | 5nXDfu13injE3xFii2KWeeMAaZWcXMz6hg+3Xyue3IHoJLkBJJ+KuClYlsa9E3Sm 11 | 8HBylLyLLyH0ByWwfNe0oVQof9HY3EYvoDjI+ITjvxhUOGBnxX1JWjBbluaKorbN 12 | 1m+auwg5YjpqBj69WmVZbVlej/qNNnex4mc6CvZIJS0s1LZ3fbJwdNJ8v/pqcOQC 13 | PjY6Ik0cw1tbvzmWMsli0EN0HjPbdkeEei113fHAiRW1f3GfkUolB3x7XCArSfwV 14 | esW9d8xAnqvgDbp0dKvkU5sCAwEAAaOB+jCB9zCBnwYDVR0jBIGXMIGUgBSt+E/R 15 | xEvarej82sI5loKzutWp0qF5pHcwdTETMBEGCgmSJomT8ixkARkWA2NvbTEXMBUG 16 | CgmSJomT8ixkARkWB2V4YW1wbGUxGjAYBgNVBAoMEUV4YW1wbGUgQ29tLCBJbmMu 17 | MQswCQYDVQQLDAJDQTEcMBoGA1UEAwwTcm9vdC5jYS5leGFtcGxlLmNvbYIBATAd 18 | BgNVHQ4EFgQU7OlZywpJiBcVley67QNjyXG8P1EwDAYDVR0TAQH/BAIwADAOBgNV 19 | HQ8BAf8EBAMCBeAwFgYDVR0lAQH/BAwwCgYIKwYBBQUHAwIwDQYJKoZIhvcNAQEL 20 | BQADggEBAGQS6rf1UW2TVAmlGaFRbvp8zkEN3DaJUkoZKvqVP7ppAPEhaZqeebB6 21 | liOGECK/9sBII7KRf9Rygc/mhF8Y7beLkTwyIDUpnU5vH88t46pu5LjYg4IKi+dM 22 | 2fOrRd6XKSvxHYUb+jVhLJaD57F4sDCe2HboidlUTgSmEpVc3jhwqlgW29JGK0Fn 23 | 2njubCyHj4f5opI6m2QozbZ1G4EpZ1JQ2qIXXazKyttrnSf04DnL6SWmEaqrWBIx 24 | awXJwBc4oM36bfQj+7I1KblPxQz83gQ23+ZYP11FtwXPM6yLL6dPyEFrlyS/s9Fo 25 | riSb6eZlzxqBllDp9p6oroR4wZk6X0U= 26 | -----END CERTIFICATE----- 27 | -------------------------------------------------------------------------------- /src/main/resources/searchguard/certs/kirk.pfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bbossgroups/elasticsearch-example/1113e1fafcc39d642102873dce4a7ea3943a8f92/src/main/resources/searchguard/certs/kirk.pfx -------------------------------------------------------------------------------- /src/main/resources/searchguard/certs/node1.key: -------------------------------------------------------------------------------- 1 | -----BEGIN ENCRYPTED PRIVATE KEY----- 2 | MIIE9jAoBgoqhkiG9w0BDAEDMBoEFHeesvAN/O/MCHvHHTsDTBPYXETnAgIIAASC 3 | BMjqP/xHAyrdtMY7OrvqLKxfGgnv/hq/eBak7j4nMFiO+zh2bMsx1djsvJYy2Nxc 4 | zCSacAkMh+Z/n6zUisL5lASUoc0I6IPb9r+nTGIikhiw/T5mVn7/rPAVw5Od4ZL3 5 | XZ+vpBmRPsvhm94mqRJnhdsSS0jCItPvC6y8f4c3Ie2XEnSVTLJqRjgBkLecNcnl 6 | h1yB2CAz+AqkIdIThCFXzw4NrTw8aJbc2TC0T52d5SqpocbMNpv2v70kza+Mm5HS 7 | GbxJ5PHITKkCsjGsEAKE6NbnxKrETlSs9C1M2+CRvpxgcIfUdAfIiS5P09aY0qEU 8 | 9n6GYNtBK69C9iRxyByq9XFGH3s5wmpsHcsBijYzDeKN24I9LT4M6yGwgV9CN+S3 9 | QJ0pyoDoCKKvAAyKFRkOKptKv+8hyjQjMlYHMFrPmadl4i9b5Y9C0gW72Agznpzm 10 | ry7fFh36BQP5D2AlrbuFWMak38hJfQoRoDG42PJ37B9e/EeV89leXF7Zxc+zD08e 11 | 46MsTtBRKlmo0fyzk3iTQrxxG2Uejtguy4FViwv5f9Xj+atr/V1MRyhJZXD8gzyi 12 | dRywKNsVZg6VRrywiPOcsHeUo4rZuo766yg1CI4N5OnIRROn+EU9LAojUvB5SnBb 13 | iaUnUDvsyPZlfA+T6ea9WVqHJ6khD5KmD8AUCVPE3vaCh7eII+t63BEGJCr0csFD 14 | xga9zA3/klJkqrccYCb0IuClVP3cNwACvgJJRTsA48yMc+6VNXJXDRr7H+HlMKBR 15 | NQMK3LPbZskCUzIpePsUpz9fIEcMAZv+IEj8lT++/EYNvehFBHthiISTfYxR/l9B 16 | 5sbuCy0M89Jjnhv6dq/AvcHyv/19DSHhZetLbA42FE4oS65Ervv/FCZon8UHqiYL 17 | hnHz4DgZfj+BQN1gSxiZf63g97OVs2yBTcvz/PxfZ38F2hm24aXE6RHBx46Mywvb 18 | YJS0fusq68dt0s43lWo59IfbQl8hCGv/sfh1ESdxZ0FbXe8/yuOhpe7N8ZdEz2Z9 19 | p2kfvvdQQ8jC/+MwxZB8Ib1EEzpvHMvkoJUOYpnnn+kBsprcXj1pIdcNsM281hXo 20 | SyeVZY2BhEwFQV4UViBN9/1WwCy/2mP+FpMLn9aAOO8+hPRAL/8yG2hhq6trNGIb 21 | EWcPVLHWx/lVB92xxYkPW1bhf069n0iomtBzy7D1d6EncSkjYG5MQpr+xJsprgE/ 22 | nj0voMNy+zY/wlNRZko9MrsWbhyg0CQ2WwunAmtpv7KCByHSIPikgy8HD+LAeiRX 23 | 33b4X+hkxYjbZczlu4SNSd5QwN5/mjiUVnVDgCj3wwHpUOqMPV74a/U3CwsAPjoe 24 | 8T0tm/cp6pXFdAYvi2xEGL59zbm9bzDV7/fCVH9FO7LtvB3fLUrKwMqxwfIXLIsI 25 | JHr53c9QtJFy+BjT4jOIQjKDnge7oTXm/6LnB+XzhHZhwNQzoDI3vwIk7zrShVk1 26 | LWsgXf/DYcZKNSaebJq5dmuBaU8bmEQgZGw3bOY10Epen1ElXM1AxAiCNtphA0QI 27 | zcowYROMJ4pPCV32yzvvnRp36PgfCE2KIjHx7KRlaQYmN2yEAwsSkhOAuDPXX51J 28 | o3xSJ/tB2krNNFEcP3Fhdr0+wrBgadlKTt8= 29 | -----END ENCRYPTED PRIVATE KEY----- 30 | -------------------------------------------------------------------------------- /src/main/resources/searchguard/certs/node1.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIElDCCA3ygAwIBAgIGAXJzB76EMA0GCSqGSIb3DQEBCwUAMHUxEzARBgoJkiaJ 3 | k/IsZAEZFgNjb20xFzAVBgoJkiaJk/IsZAEZFgdleGFtcGxlMRowGAYDVQQKDBFF 4 | eGFtcGxlIENvbSwgSW5jLjELMAkGA1UECwwCQ0ExHDAaBgNVBAMME3Jvb3QuY2Eu 5 | ZXhhbXBsZS5jb20wHhcNMjAwNjAyMDMxNjUxWhcNMzAwNTMxMDMxNjUxWjB0MRMw 6 | EQYKCZImiZPyLGQBGRYDY29tMRcwFQYKCZImiZPyLGQBGRYHZXhhbXBsZTEaMBgG 7 | A1UECgwRRXhhbXBsZSBDb20sIEluYy4xDDAKBgNVBAsMA09wczEaMBgGA1UEAwwR 8 | bm9kZTEuZXhhbXBsZS5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB 9 | AQDZSGn/ky405JkrlYWRWsA8eOU7X0kkTwwrEkKpO0010pdbjzjM278UOr4+oAIS 10 | vwNz+MqpN/eHF5FxDyeFVL/MiugyTlzno4zIXrr6jqYnbiciqwEn5ISYcOAOca/h 11 | 3wqgwQb/Pt8bmLB0DSDY1FLgAt5smnxDFnZlUwofi50pYkwYv5m/nexp3kHxxIGW 12 | ewlqfUOYV/PJiIOjUhP+0W3Ig+9QOUis5dHxtMICZiKdvPQY9bl6d5VanHds1f/p 13 | IjXQpSkfblcEtc7rmrlRgeK3H2mIg0uGFkaXL3iptzWRQDmLB4NGY99vQtu8r6pB 14 | JmZ4ogxZpna5S6YKtpRhJLYnAgMBAAGjggEpMIIBJTCBnwYDVR0jBIGXMIGUgBSt 15 | +E/RxEvarej82sI5loKzutWp0qF5pHcwdTETMBEGCgmSJomT8ixkARkWA2NvbTEX 16 | MBUGCgmSJomT8ixkARkWB2V4YW1wbGUxGjAYBgNVBAoMEUV4YW1wbGUgQ29tLCBJ 17 | bmMuMQswCQYDVQQLDAJDQTEcMBoGA1UEAwwTcm9vdC5jYS5leGFtcGxlLmNvbYIB 18 | ATAdBgNVHQ4EFgQUI4hWx8uwb9f66zWlxASN1p+ElDYwDAYDVR0TAQH/BAIwADAO 19 | BgNVHQ8BAf8EBAMCBeAwIAYDVR0lAQH/BBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMC 20 | MCIGA1UdEQQbMBmCEW5vZGUxLmV4YW1wbGUuY29thwQKDQsFMA0GCSqGSIb3DQEB 21 | CwUAA4IBAQA4mcF4b3PPjDei0kM6IVIU71I0Fo+JxbNJQhZOpzuNqN9kN8eT1jmi 22 | c/xS21yY4qeGF5K4aOL4MmhXxb/MG7gtgZeqJDBMgIvRuZ45ds5wm2CtzBThETqG 23 | qY5FUVldmLbwMaCAYzg98IWjhExt2a8KbsmRoWqOZVcetq9us92hRLuTF5Wi/nh1 24 | z8woxOHnGzsCiul0bs6We63ZI8PRskSEye/n2hh0AZm8KHQsvHLGgsa0t1mQ5Uj+ 25 | NixV0Lqwg3QFC1/W4bOf5P09BM1AYrIhNV0dyB2VOb+4WMR4m35yZavSlHcn7LDj 26 | r7c7tLKCKP+MNlmKP8TuiekNEtd+dUaZ 27 | -----END CERTIFICATE----- 28 | -------------------------------------------------------------------------------- /src/main/resources/searchguard/certs/node1_elasticsearch_config_snippet.yml: -------------------------------------------------------------------------------- 1 | # This is a configuration snippet for the node node1 2 | # This snippet needs to be inserted into the file config/elasticsearch.yml of the respective node. 3 | # If the config file already contains SearchGuard configuration, this needs to be replaced. 4 | # Furthermore, you need to copy the files referenced below into the same directory. 5 | # Please refer to http://docs.search-guard.com/latest/configuring-tls for further configuration of your installation. 6 | 7 | 8 | searchguard.ssl.transport.pemcert_filepath: node1.pem 9 | searchguard.ssl.transport.pemkey_filepath: node1.key 10 | searchguard.ssl.transport.pemkey_password: HUsyHDGxo9mR 11 | searchguard.ssl.transport.pemtrustedcas_filepath: root-ca.pem 12 | searchguard.ssl.transport.enforce_hostname_verification: false 13 | searchguard.ssl.transport.resolve_hostname: false 14 | searchguard.ssl.http.enabled: true 15 | searchguard.ssl.http.pemcert_filepath: node1_http.pem 16 | searchguard.ssl.http.pemkey_filepath: node1_http.key 17 | searchguard.ssl.http.pemkey_password: 1k0dVQKtFgOX 18 | searchguard.ssl.http.pemtrustedcas_filepath: root-ca.pem 19 | searchguard.nodes_dn: 20 | - CN=node1.example.com,OU=Ops,O=Example Com\, Inc.,DC=example,DC=com 21 | searchguard.authcz.admin_dn: 22 | - CN=kirk.example.com,OU=Ops,O=Example Com\, Inc.,DC=example,DC=com 23 | -------------------------------------------------------------------------------- /src/main/resources/searchguard/certs/node1_http.key: -------------------------------------------------------------------------------- 1 | -----BEGIN ENCRYPTED PRIVATE KEY----- 2 | MIIE7jAoBgoqhkiG9w0BDAEDMBoEFHDgwCAWvvhq8OBbxR9fG5SxRHENAgIIAASC 3 | BMBZ3iOlUxVvymgM4SNSXdgf3DcC836cnIRz27G+xlHUHVV/avycKe8ZkklMZG/s 4 | kdlTvhINP5V/shNKf2kM7Ik+79HdV7VRDT2kJb3dBNiDyBxJbvSDArMfhx9o1I15 5 | mbswoQ4zhMOfPG350nSSlJTNIbagz5Ft22rNEjFSiu7lpLQl2pJqN6S5gi/k5xp8 6 | +losA3cGxhzORgC5+DrCGgewcnjAytDK11IlotKPsdOWmWZB9U56eVMbqxbP3hIl 7 | yWJBE1AZDFvYeuLbxCwa44csEMQY/tp+gexbnUJT+rm79lmopQhmOD12aN0qcBeU 8 | TQXv4wOia2DR4zpf6wLIHKpIcMnoRaKhSQHjplLTmlOIF97CFtiXz/6+waIrPfZo 9 | ZL+evsNA5IPKzH4IwxrnBwidXLZcRhJs3puwK8SxvmKLZbnUhY/LWKL44L7J+1oA 10 | qBONVcu5pymFG0MUwMbcatWxuL37fnJY0AXQ+sKB3a9NwRC0TtDDRkdEXR2GPqoX 11 | SlYg/qUv51jhrWRkcBEezCAG6t6lbzRRLEVDuXbK7FT7P5Wj7NRqHF5hwj6GJBke 12 | Bd3EmDFKKSDcmXMsS1dBWKbrnyd/McgT3YFO1v5eR9fhflybRfjDwkXIVdRV5D+h 13 | +ufdeLOMdtWudcIzVHBqMmfudXv+tRWXiuT7IAzBiZQUuVC1E79trnSz1k0sB7nz 14 | cPwu7NpU1vGI7k+mvjd/gwY6QLm24+4wWEeyi8tr+5V/hmaAwYONvTXyRXjlWBXF 15 | JbV+rt2RrdiBGj+saPkQgjGgvfcY1z/7AgN8XIunaH8iJMdrtNUYWjztL71yhbkg 16 | jJLwVPL/HLvxMCP6U/Chnh36at5gWmC+9Zt97g3dDVlCX3RJmlJtyiPJqDb3nSs/ 17 | BOcruwYn6dJWdZc8gfGG6cj5owrA4h8Hibb4UtphZD1JtJyYM9+sSoGSolVTytoh 18 | TWQ9KcM8ZueS8ei73IWAERVE9SbJRvLJX+HVWnek3rfbEUnL1wLNPXGaDQ08GMoZ 19 | kkxzmN14M7u7tkGJsxi/EBX9sg+I/9Wkb4eEXUbSQkSVgcMn5AAmZ3Gk4ktRMtAj 20 | D0lMpOCvKXvUdTQYDSKOyRe/WCqvYO16YbpyDYLiFSjlikhWSYCrCxAbQJHKYG4t 21 | ibVRiBatLqcxPdNM5gf5WGltSmD4BSA8zRkQHl3/yBwbdC5MowZDE3DxbZrc/svw 22 | kXcTDMuqvnXcZ0VuKqU11pM9Mkb50yPU8BKEXM4gg7+loPEsDs1n06X32vubBMw/ 23 | jhyKb55EWJCOpAcYPVnPM3SCyRYsUjy4PLtw/L63y8o28DaDebEc9gHl7SN5txJq 24 | RDixWm5si/bMekuHQVuEkR85kG0so2kMg3Yk8VVPr6Q9QZv0CH5ueqofspR6ZL/U 25 | pbylct6ApOdRmHan6YvKoQ6kNiP+274POnnSq2coYQCKxavuBkGD4fmN21UwVR45 26 | u0d52jd38hCLbg7ydUSqhUzMo3RSF4IsHQIfUnE7MB3GAP5oS+tSkebncKNojh/H 27 | zgpJJNSScV+4U9EZyK+Z+4bHetya05CtdGLps32hbJlVeTrwyT5NhDswpLQgCPYw 28 | kf2bOMXtZhwkbssjqqg9dFWb 29 | -----END ENCRYPTED PRIVATE KEY----- 30 | -------------------------------------------------------------------------------- /src/main/resources/searchguard/certs/node1_http.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIElDCCA3ygAwIBAgIGAXJzB76FMA0GCSqGSIb3DQEBCwUAMHUxEzARBgoJkiaJ 3 | k/IsZAEZFgNjb20xFzAVBgoJkiaJk/IsZAEZFgdleGFtcGxlMRowGAYDVQQKDBFF 4 | eGFtcGxlIENvbSwgSW5jLjELMAkGA1UECwwCQ0ExHDAaBgNVBAMME3Jvb3QuY2Eu 5 | ZXhhbXBsZS5jb20wHhcNMjAwNjAyMDMxNjU4WhcNMzAwNTMxMDMxNjU4WjB0MRMw 6 | EQYKCZImiZPyLGQBGRYDY29tMRcwFQYKCZImiZPyLGQBGRYHZXhhbXBsZTEaMBgG 7 | A1UECgwRRXhhbXBsZSBDb20sIEluYy4xDDAKBgNVBAsMA09wczEaMBgGA1UEAwwR 8 | bm9kZTEuZXhhbXBsZS5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB 9 | AQC0Myk8Sr+DDTzChti6ovJQRRT3r9KN9GaK4ndc7dxMgGbqikkbuYnF+EbvYIso 10 | 1MSSojHf5+fDYgJRGjSmg1w42Kgxsdfw3uw+UGhGNZttAC2BA3CR/iSkbUD5AdWY 11 | 2YqIZDr4PfD9nRhnDCvZtRodKAs04QdviPIspvPeNflBuHiXkmBujp9b5JtbS6rz 12 | A+SiRdPcMZTJuTOjZ6xUGkL3UEQNYzItAInV6zmt7BwhB3rZoGdOat2vekO64q5a 13 | hva5vUNG8H9v9yaba/xWH3HVbaeAx15TN4prqER/Ft42H4EohRsWEz+46Pn8gQ7h 14 | n5fm69Jbtj4tIqaXtBWluuCBAgMBAAGjggEpMIIBJTCBnwYDVR0jBIGXMIGUgBSt 15 | +E/RxEvarej82sI5loKzutWp0qF5pHcwdTETMBEGCgmSJomT8ixkARkWA2NvbTEX 16 | MBUGCgmSJomT8ixkARkWB2V4YW1wbGUxGjAYBgNVBAoMEUV4YW1wbGUgQ29tLCBJ 17 | bmMuMQswCQYDVQQLDAJDQTEcMBoGA1UEAwwTcm9vdC5jYS5leGFtcGxlLmNvbYIB 18 | ATAdBgNVHQ4EFgQUkEu6tanbK99IQ0NgrHqCZYYhbJAwDAYDVR0TAQH/BAIwADAO 19 | BgNVHQ8BAf8EBAMCBeAwIAYDVR0lAQH/BBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMC 20 | MCIGA1UdEQQbMBmCEW5vZGUxLmV4YW1wbGUuY29thwQKDQsFMA0GCSqGSIb3DQEB 21 | CwUAA4IBAQCTW9LpjUTGENwovldhW3tjSDh5Tk+LRaNRBCTQ22dENzGDxAWN1DjQ 22 | uhbk+TdAsRDk0M4Kg4IS9UE5bqNXiSW1GPFNLSi6bQuYFcjCPky4MqogUhsi0Plh 23 | eaqJEXrqmcQogby8yD1UWHrnhV+gY0DDYW34Ju4fJvRIiEwzuCE5K1oFWlrW/sbS 24 | 4AyDwBOfiBlqAvHYkLRSA4z1fTIe0YZifOZBNrStdBlEUgPHJjyx+v7U4Y+JjL2+ 25 | 5WmGfSZ5Oy0LKwTk093iG0D7TF5rQWJzod5VADO9DC+iPuGJwJR4d3bGAkFX+/ck 26 | 9IQSoLZGP2x3booLSK72oP7b3DttU3Y5 27 | -----END CERTIFICATE----- 28 | -------------------------------------------------------------------------------- /src/main/resources/searchguard/certs/root-ca.key: -------------------------------------------------------------------------------- 1 | -----BEGIN ENCRYPTED PRIVATE KEY----- 2 | MIIE9jAoBgoqhkiG9w0BDAEDMBoEFBwRif/V6/JjICdbS571MofAm7WvAgIIAASC 3 | BMgDS7nrcMPSElM4EXF7fG/bu3ZYBw2X3TDYOKAWWdIysWtxMjKWHGJfnTKripdi 4 | ouQ7kwp9nLsUkIl12OVKTeTL9wdB6vpaW7rxYfrrvZar+FKsHFd0zWhsRnBoI3vn 5 | +gm+G1xSMrfanR/lM0A23XCvS6ul0WnpTFHUIETbYzCc9DTYur7841BnE5Zt1pYI 6 | gkzkPcbY+H/S6a4Gnkz1kbCCZCgmQr3DCCbLd3DbBTUVlS5jG/UVyYthwF4kNWHp 7 | +MTeaR/eIR+sFPsRwjcZ4ffXe5JTVJuu07pOjE03w6oLoAX1ZePIcf1terNA34nh 8 | 21Gp0t1U9x/HpMOXe0cdk9YRZYTI9TcGeX1WqGDkD0UtjQPUOfOD/q4XBw0s0qWh 9 | idROxXUXSaHOXyXb1SZCnoU26/pb0QYqzrEeKT5tx6tNEFVVdiO+B2tKBxHOK9WI 10 | EEck0stAsv6kUr4Iqjc3wCPPNM/cSRqsv/+NCaMtXWs/Dxb+spuRcquhJFwhqWFy 11 | AvA85CTV/vK4XRAMzIUJZkb1cp+vPyjAsoJw4hTtE6KN5nOIzuV+WvFK8oDSkd9g 12 | brDGbFJ4+CGPvF3iW/Fv9G0g47hM9h2TCcJQ6SBSUTnmznL4unFBHGkptvfSXyiU 13 | lZ+W1f3aHhmmpZXrhgZZnMtVyjoFW4fnINNJdjFa6nitSBAqnZGEGhKa6xwjj3HP 14 | 7q3kcxyfy9PyIftgvOrMfXHdVyTAQZOIjaaKUcSaW++fkh0f8Loy3H16EWqYnnTr 15 | 77+oNc/M0f9P1xbMgSn4McTrxPf4T71OwLTjum1z6sb+WgpNNRfdZyOcnUgxjkOH 16 | Ux0MFpLNhaPtAu1RDytjiQOuW7H3WlOD983QjnJZN/XUXLVwdBo7vlHTgBVG1+6N 17 | yJBmNS1CMThkgyd31c4LoPwHAzm7BImecYplW4kLT6MmRMG8m47Bkfc81XG0haEN 18 | 29FH/UDSNkQ+7Q3I+UXOiF1lBaD8WNWNv4pZIjWTxGoxxq3/+LyAVRvY3sPY/MF7 19 | Si/Sj9E7sHg71ACA6oAwRTbh7Y6AHro/IMKL1zRfrE0b6v0WrffSqm3tTo7QXmpU 20 | fGDgmSekH9OL0nJxG4YSk+4dZM6HTmjcGPJq5sNwCGszpZ3blcyH5hwuVrZpmBhS 21 | 2Xo2tBUF4FPfh+WKqhC9u8VNrRi7oYfHTy58oJgDRzbJOj7blbu3ZfMSBUssW1eJ 22 | Qn4F0snlvC4dPE7CDfsFLbBDyY2DryTbHhRWu7PbfKx/VGZYWksiLZMppQ4tRTWP 23 | OdhzdXbyT+BGpQZ7g6FeNKDByjJMupRdQxf1z4Eaxn2aIcYSnvKwmMWCgYNXaAbt 24 | cgN+GplBMc+xriaLXQ3JR9dKcCG2m1W4BQznYNlThblRlUyBQibWjylkjdjGalfN 25 | G/2xCapNLBLx89m8xGvk7ZYuFskUyCuE5HYUGuEBCYebfbKOmbX4iP68gc3XKiwo 26 | 4PdSgvXVsr0lnauFT4Wx6Yvd0vOP442l0dYnrOlPv+rGwJlL6tjg6yS9RyYndLVv 27 | bdHZA6VahKAP+m9XVh+CNy4rItdzkLG0GQxj1rch0hUwn9wCHp/nHMdjMLD/Mkij 28 | ag1w6QhDZI34VHUnDvrzzsLlX+UBko/NCxI= 29 | -----END ENCRYPTED PRIVATE KEY----- 30 | -------------------------------------------------------------------------------- /src/main/resources/searchguard/certs/root-ca.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDyDCCArCgAwIBAgIBATANBgkqhkiG9w0BAQsFADB1MRMwEQYKCZImiZPyLGQB 3 | GRYDY29tMRcwFQYKCZImiZPyLGQBGRYHZXhhbXBsZTEaMBgGA1UECgwRRXhhbXBs 4 | ZSBDb20sIEluYy4xCzAJBgNVBAsMAkNBMRwwGgYDVQQDDBNyb290LmNhLmV4YW1w 5 | bGUuY29tMB4XDTIwMDYwMjAzMTY0NVoXDTMwMDUzMTAzMTY0NVowdTETMBEGCgmS 6 | JomT8ixkARkWA2NvbTEXMBUGCgmSJomT8ixkARkWB2V4YW1wbGUxGjAYBgNVBAoM 7 | EUV4YW1wbGUgQ29tLCBJbmMuMQswCQYDVQQLDAJDQTEcMBoGA1UEAwwTcm9vdC5j 8 | YS5leGFtcGxlLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAN6Y 9 | W1EtBcbOYwxlTNghq+XWKYqEHG9+rAetkijM5n27HPnPAZ2ntNi4Q1szrHBnIfhv 10 | l4yL5asXEMy3hsP+bE1VC72nwoeCdv0lZZvaXQzmPCBW2rvJERa2ZX0Pbw43gDFd 11 | FFiKkAvJnWUmQEVZeGWEsEFewa5GYpmJDiDoAkiC938DBa0lI1fjZGdRWbaaaOQ1 12 | xo3CAhJlBP4/+ptjxhMlqgLf7Und3bZXQ3Ei/dm9Yu343dlCPoiRGOcWjAyn8+Y2 13 | jtedQnFCvMi8P+n8LJMaK8Jy8qo1r4pSKyKsalncP7fK3J+o3sPCyR3OCpKNdBnZ 14 | vBfXb7/zAy1Km0E6UrsCAwEAAaNjMGEwDwYDVR0TAQH/BAUwAwEB/zAfBgNVHSME 15 | GDAWgBSt+E/RxEvarej82sI5loKzutWp0jAdBgNVHQ4EFgQUrfhP0cRL2q3o/NrC 16 | OZaCs7rVqdIwDgYDVR0PAQH/BAQDAgGGMA0GCSqGSIb3DQEBCwUAA4IBAQBDm3XC 17 | FtNztliQQ/oNwRJjQRN7Z2H5TyHtaV2hL7GTUuuAqXXZM6tHgYcjb7Z6jsk97gOC 18 | qoAwuclo3boj6y35yUp9FJCZHZXFHTXPrZ8X/2MDzYR3Vp7snHMRElUtFkySbhJf 19 | vlW+imZsUFNYcPWzkrZs4RbuXx+G3/wVzxqP91+wVphB7NaWfDDNuF397yU4pjT8 20 | IEJjowqThRnkNALDd8zusEXbiF+Nv8h9CQidzuyuIYtyW+TvDrltTJC8RwxKYCc+ 21 | OVbvxoIRxqW11nvQTVYtzoExMBUXB6rlTgr6IP6WrG4p5jTJCD4qwh+HVVD8FkcF 22 | qHyCl3pi4GhiI3iQ 23 | -----END CERTIFICATE----- 24 | -------------------------------------------------------------------------------- /src/main/resources/searchguard/certs/root-ca.readme: -------------------------------------------------------------------------------- 1 | The private keys of the root certificate and/or the signing certificate have been saved encrypted with an auto-generated password. 2 | In order to use these new passwords later again with this tool, you must edit the tool config file and set the new passwords there. 3 | 4 | ca: 5 | root: 6 | pkPassword: YFIBzhTiOkic 7 | -------------------------------------------------------------------------------- /src/main/resources/searchguard/certs/spock.key: -------------------------------------------------------------------------------- 1 | -----BEGIN ENCRYPTED PRIVATE KEY----- 2 | MIIE9jAoBgoqhkiG9w0BDAEDMBoEFI0OPEfkd+IZrPPVhLRr6uEvfyLjAgIIAASC 3 | BMiKiFWzvw7p8ugifM9D2XSmfSIoSC9Su4f/NKfJFVtA1d6c0NmVdDZ8rDrofwbY 4 | b/mSJi0unJtJhjvP8acAVvYprbwoSxbwzApuzGdxNauVk0xjJFTJEYK3AH/Henp1 5 | fhE2JTKrhTlTmhXXE74PYz0FkReB+HfqQVk2Afo0iTd8hpGrHtEdc3laFPN13W6O 6 | VVEb+Uh3yitbJPIYtvr5L3pAITrpdJ23cRyUGPcnA0bDE6WqftQIW7Y4BBGgWFGK 7 | SCvMzDidpaaD6rh5rGtQvZOUfMT1I21zLqpfLYV6ch9E8L3N/460367zSsWrQsh3 8 | TkPA11HXNaeSq7pvQT5GJ5ZkXy/EylLzDrITdYsr0gDAHgdVWxyE2miyccv+MlBR 9 | dfRvzD/VBe+e7bwmXJfYclSAXi0x0t5JSDd+RMFhYthWL1DLe8BxWXb3ui596wKV 10 | Wn1NHnqmpLUhrhkJhFMKYS+WSUuuvxeEZrUwSMCf4autfClcM32ywieO47X6u+SI 11 | KjvJvXOesVj8xvVmpbSbOZAtOzP8KvGuQeCbCKXv5v0v7RyuPFAXhxYQA2bKnZ6T 12 | i315uX5EpA7IZB+8/MbymZAx12e7a1saTIaJY/0lJyquOOa8H3GA3k6QeJxzfua/ 13 | qy3k9EexfOMf0A5c9nZJ/we1X2a+pf8tKO1KEX6u/m7mvZBFqGnVQ36iLI6OP+zi 14 | BXkvmcaopv74wKotr4olrJvXukPHgXT6rxm1T78P/l8uUu0w1/zcW+nay6BJOp1I 15 | veJZqUCgrT4Uol7E956c5B8aCG8gJkzjFYsnBQgjySVtYZP2qOiLcEleY1ZXnPGQ 16 | Vdg9jpxn0Ldt82BQ7HZcpa0ejCb1+rn2LFmqNGUGMjQAhV62ZvcL99fOwOYLOVX8 17 | oxviDcxgPCCyDQXNP0xg0ytllqf0X/0hAMr2W6Us8jRBz4k7o/+OjrL4G4a0wWWJ 18 | P1sh5llA+npuJnie4gIXZ9lnJV8HIoASBvKvyyj246uOajLF8FOqzLig/05TFHAz 19 | 6TstAXbXt4nulpElr1FOsLVVHRnxuOoAaEMM9qmrKbiFDeBhqjbVFvZarEX2JMp9 20 | jv6AJRbG4be6ASracORZAp9AperSK8wHGYZtylwyhCUcxXkpEADSBTP2Mf74ArLK 21 | frMLH1WgpAvh9uYiqlHH/FVHFsBTXPOJek1pnibfTCiAo9hWMs/emMmFkxkHq7ve 22 | EX2CMYq+al/+rtoXtzOJxvt2K0+rRPMtoZrwxubkMBMrk2oDzTCXqXVrdlts7uFV 23 | 42D9MIi8dHKZ+KOsHtBctPqKXBWgiVDaAhs1GQ8IQcrQsS1VOPriGoPQuICdVmkr 24 | m2cTkF0ipmEPJBK9cY49H0Yrw20ToGuZ+hCOkcUDwy6URZ2SKOxvGujYAyCsKAzO 25 | Ewq4w8Dyetgx1jsZbidT3Xe5BAkprRPNeLHVfKGOsXGi+cDy+hhiGhglFx+0hB8N 26 | zHX09UQdImpy+/bDp6bp7whIo44zTXoc0TIge8l2+34v+56sgbNdHobJ7+SfnSQk 27 | DA31tabtAla9uirqh/TwhmfEkKKLTFDIncGy45IWNW2qkV1EIZK4CtI/FVz8ROv2 28 | Mb9ocBheWAdwNujKxvt4aWSgYinPGS7+FUo= 29 | -----END ENCRYPTED PRIVATE KEY----- 30 | -------------------------------------------------------------------------------- /src/main/resources/searchguard/certs/spock.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIEZDCCA0ygAwIBAgIGAXJzB76GMA0GCSqGSIb3DQEBCwUAMHUxEzARBgoJkiaJ 3 | k/IsZAEZFgNjb20xFzAVBgoJkiaJk/IsZAEZFgdleGFtcGxlMRowGAYDVQQKDBFF 4 | eGFtcGxlIENvbSwgSW5jLjELMAkGA1UECwwCQ0ExHDAaBgNVBAMME3Jvb3QuY2Eu 5 | ZXhhbXBsZS5jb20wHhcNMjAwNjAyMDMxNzAxWhcNMzAwNTMxMDMxNzAxWjB0MRMw 6 | EQYKCZImiZPyLGQBGRYDY29tMRcwFQYKCZImiZPyLGQBGRYHZXhhbXBsZTEaMBgG 7 | A1UECgwRRXhhbXBsZSBDb20sIEluYy4xDDAKBgNVBAsMA09wczEaMBgGA1UEAwwR 8 | c3BvY2suZXhhbXBsZS5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB 9 | AQCxxn29fzHOiM+PkYKgsam8w3gtBJ7V/BOJYhw/kIWU2cD8Lko2gFV8cLkZdeI0 10 | 7NgRtz+ogWvMD6YPfCEKXAtZDTC0KysW25jLsRlnLAuMdgvl1rHv4fYzlZWGZOVG 11 | f3MPjmfdoRuZmQz49XIoMRVv6ry8ZrTsg3JoNL+thsUyeAuyZd12BReqDIqidiWu 12 | K5z+lAiHBi+Eoq35b+C0FTOPGvsc1j7OoVfrrKAYbDS1IoP8YJ0Wi2ziv4+GVVoH 13 | 4OzPvtbqjka9a9IpCjNfEqFzgWw19Yvxjt2LDZzMsjR3ud5PJdmQ5khMXSGp8cdd 14 | d22mZQjkwibw8UbJRhOp+5ORAgMBAAGjgfowgfcwgZ8GA1UdIwSBlzCBlIAUrfhP 15 | 0cRL2q3o/NrCOZaCs7rVqdKheaR3MHUxEzARBgoJkiaJk/IsZAEZFgNjb20xFzAV 16 | BgoJkiaJk/IsZAEZFgdleGFtcGxlMRowGAYDVQQKDBFFeGFtcGxlIENvbSwgSW5j 17 | LjELMAkGA1UECwwCQ0ExHDAaBgNVBAMME3Jvb3QuY2EuZXhhbXBsZS5jb22CAQEw 18 | HQYDVR0OBBYEFKd5+4/oxK+Pos/nX+MYaCOYri4dMAwGA1UdEwEB/wQCMAAwDgYD 19 | VR0PAQH/BAQDAgXgMBYGA1UdJQEB/wQMMAoGCCsGAQUFBwMCMA0GCSqGSIb3DQEB 20 | CwUAA4IBAQA+KTU2UV/FTE/c0BCtqk779nMYGdOCLKICPo8afGrcOZk0VNordsoy 21 | 2zhYRR9c1MMPIs8qyjXfezNiBEPGxvV79dSFbvUfFBWwTsKXfHgVTQKUlT/l8GSW 22 | oWNI6NMuwYFcTIwHFuxAJe29hiJpuBur/mUWmvyBekpHcvnB67c2obvQH0rEFZZQ 23 | F7FyVwo1OnwIdIZib60tKFmVX6VC0d0aFgvf8jnoWjepUrGQyHxYArEtIypGYb+A 24 | VfP0s9TH/FnlML3E4YRMorkqom8gIrkpvepqrH9FazeAoLDQMzcoHZB0ovpd2nLx 25 | Tj+QhqDFH3M/bk2YXeD13Nu3uBQWuJXj 26 | -----END CERTIFICATE----- 27 | -------------------------------------------------------------------------------- /src/main/resources/searchguard/truststore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bbossgroups/elasticsearch-example/1113e1fafcc39d642102873dce4a7ea3943a8f92/src/main/resources/searchguard/truststore.jks -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/HighlightSearch7Test.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest;/* 2 | * Copyright 2008 biaoping.yin 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 | 17 | import org.junit.Test; 18 | 19 | import java.text.ParseException; 20 | 21 | public class HighlightSearch7Test { 22 | 23 | @Test 24 | public void testHighlightSearch() throws ParseException { 25 | HighlightSearch7 highlightSearch = new HighlightSearch7(); 26 | highlightSearch.initIndiceAndData(); 27 | highlightSearch.highlightSearch(); 28 | } 29 | @Test 30 | public void testHighlightSearchOther() throws ParseException { 31 | HighlightSearch7 highlightSearch = new HighlightSearch7(); 32 | highlightSearch.initIndiceAndData(); 33 | highlightSearch.highlightSearchOther(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/HighlightSearchTest.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest;/* 2 | * Copyright 2008 biaoping.yin 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 | 17 | import org.junit.Test; 18 | 19 | import java.text.ParseException; 20 | 21 | public class HighlightSearchTest { 22 | 23 | @Test 24 | public void testHighlightSearch() throws ParseException { 25 | HighlightSearch highlightSearch = new HighlightSearch(); 26 | highlightSearch.initIndiceAndData(); 27 | highlightSearch.highlightSearch(); 28 | } 29 | @Test 30 | public void testHighlightSearchOther() throws ParseException { 31 | HighlightSearch highlightSearch = new HighlightSearch(); 32 | highlightSearch.initIndiceAndData(); 33 | highlightSearch.highlightSearchOther(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/MatchPhrasePrefixQueryTest.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest; 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 | 18 | import org.frameworkset.elasticsearch.ElasticSearchHelper; 19 | import org.frameworkset.elasticsearch.client.ClientInterface; 20 | import org.frameworkset.elasticsearch.entity.ESDatas; 21 | import org.junit.Test; 22 | 23 | import java.util.HashMap; 24 | import java.util.List; 25 | import java.util.Map; 26 | 27 | /** 28 | *

Description:

29 | *

30 | *

Copyright (c) 2018

31 | * @Date 2018/7/31 11:30 32 | * @author biaoping.yin 33 | * @version 1.0 34 | */ 35 | public class MatchPhrasePrefixQueryTest { 36 | ClientInterface clientInterface = ElasticSearchHelper.getConfigRestClientUtil("esmapper/matchPhrasePrefixQuery.xml"); 37 | @Test 38 | public void testMatchPhrasePrefixQueryTest(){ 39 | 40 | Map params = new HashMap(); 41 | params.put("queryCondition","bl"); 42 | params.put("maxExpansions",10); 43 | params.put("from",10); 44 | params.put("size",20); 45 | ESDatas searchResult = clientInterface.searchList("demo/_search",//检索的请求地址 46 | "testMatchPhrasePrefixQueryTest",//对应的dsl配置语句 47 | params, //dsl中需要的参数 48 | Map.class);//返回结果封装的对象类型,可以为自定义的实体Bean对象类型 49 | List datas = searchResult.getDatas(); 50 | long totalSize = searchResult.getTotalSize(); 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/TestInit.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest; 2 | /** 3 | * Copyright 2020 bboss 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 | 18 | import org.frameworkset.elasticsearch.ElasticSearchHelper; 19 | import org.frameworkset.elasticsearch.client.ClientInterface; 20 | import org.frameworkset.elasticsearch.entity.ESDatas; 21 | import org.frameworkset.elasticsearch.scroll.HandlerInfo; 22 | import org.frameworkset.elasticsearch.scroll.ScrollHandler; 23 | import org.junit.Test; 24 | 25 | import java.util.List; 26 | import java.util.Map; 27 | /** 28 | *

Description:

29 | *

30 | *

Copyright (c) 2020

31 | * @Date 2020/4/23 17:09 32 | * @author biaoping.yin 33 | * @version 1.0 34 | */ 35 | public class TestInit { 36 | @Test 37 | public void init(){ 38 | 39 | ClientInterface clientUtil = ElasticSearchHelper.getRestClientUtil(); 40 | //get elasticsearch cluster state 41 | String result = clientUtil.executeHttp("_cluster/state?pretty",ClientInterface.HTTP_GET); 42 | 43 | //check indice twitter and index type tweet exist or not. 44 | //适用于elasticsearch 6及以下版本有类型,7以上版本无类型 45 | boolean exist1 = clientUtil.existIndiceType("twitter","tweet"); 46 | System.out.println("twitter tweet type exist:"+exist1); 47 | //适用于 Elasticsearch7以上的版本,check indice twitter exist or not, 48 | exist1 = clientUtil.existIndice("twitter"); 49 | System.out.println("twitter exist:"+exist1); 50 | //count documents in indice twitter 51 | long count = clientUtil.countAll("twitter"); 52 | System.out.println(count); 53 | 54 | //Get All documents of indice twitter,DEFAULT_FETCHSIZE is 5000 55 | //返回对象类型为Map,也可以指定为特定的PO对象,适用于记录数量不大的表 56 | ESDatas esDatas = clientUtil.searchAll("twitter", Map.class); 57 | //从esDatas中获取检索到的记录集合 58 | List datas = esDatas.getDatas(); 59 | //从esDatas中获取检索到的记录总数 60 | long totalSize = esDatas.getTotalSize(); 61 | 62 | //Get All documents of indice twitter,Set fetchsize to 10000, Using ScrollHandler to process each batch of datas. 63 | //指定批处理器分批次处理数据,适用于记录数量比较大的全表表数据查询 64 | clientUtil.searchAll("twitter",10000,new ScrollHandler() { 65 | public void handle(ESDatas esDatas, HandlerInfo handlerInfo) throws Exception { 66 | List dataList = esDatas.getDatas(); 67 | System.out.println("TotalSize:"+esDatas.getTotalSize()); 68 | if(dataList != null) { 69 | System.out.println("dataList.size:" + dataList.size()); 70 | } 71 | else 72 | { 73 | System.out.println("dataList.size:0"); 74 | } 75 | //do something other such as do a db query. 76 | //SQLExecutor.queryList(Map.class,"select * from td_sm_user"); 77 | } 78 | },Map.class); 79 | //Use slice parallel scoll query all documents of indice twitter by 2 thread tasks. DEFAULT_FETCHSIZE is 5000 80 | //You can also use ScrollHandler to process each batch of datas on your own. 81 | esDatas = clientUtil.searchAllParallel("twitter", Map.class,2); 82 | //指定批处理器分批次处理数据(适用于数据量比较大的表),并行检索和处理表数据源,线程数量为2, 83 | clientUtil.searchAllParallel("twitter",10000,new ScrollHandler() { 84 | public void handle(ESDatas esDatas, HandlerInfo handlerInfo) throws Exception { 85 | List dataList = esDatas.getDatas(); 86 | System.out.println("TotalSize:"+esDatas.getTotalSize()); 87 | if(dataList != null) { 88 | System.out.println("dataList.size:" + dataList.size()); 89 | } 90 | else 91 | { 92 | System.out.println("dataList.size:0"); 93 | } 94 | //do something other such as do a db query. 95 | //SQLExecutor.queryList(Map.class,"select * from td_sm_user"); 96 | } 97 | },Map.class,2); 98 | } 99 | } 100 | 101 | 102 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/aggs/TestTermAgg.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.aggs; 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 | 18 | import org.frameworkset.elasticsearch.ElasticSearchHelper; 19 | import org.frameworkset.elasticsearch.client.ClientInterface; 20 | import org.frameworkset.elasticsearch.entity.ESAggDatas; 21 | import org.frameworkset.elasticsearch.entity.LongAggHit; 22 | import org.frameworkset.elasticsearch.entity.SingleLongAggHit; 23 | import org.junit.Test; 24 | 25 | import java.text.ParseException; 26 | import java.text.SimpleDateFormat; 27 | import java.util.Date; 28 | import java.util.HashMap; 29 | import java.util.List; 30 | import java.util.Map; 31 | 32 | /** 33 | *

Description:

34 | *

35 | *

Copyright (c) 2018

36 | * @Date 2019/1/14 16:13 37 | * @author biaoping.yin 38 | * @version 1.0 39 | */ 40 | public class TestTermAgg { 41 | 42 | @Test 43 | public void termAgg(){ 44 | ClientInterface clientInterface = ElasticSearchHelper.getConfigRestClientUtil("esmapper/testagg.xml"); 45 | //ESDatas traces = clientInterface.searchAll("trace-*",1000,Map.class);//获取总记录集合 46 | Map params = new HashMap();//聚合统计条件参数 47 | params.put("application","testweb"); 48 | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:dd"); 49 | try { 50 | params.put("startTime",format.parse("1999-01-01 00:00:00").getTime()); 51 | params.put("endTime",new Date().getTime()); 52 | params.put("rpc","/testweb/jsp/logoutredirect.jsp"); 53 | } catch (ParseException e) { 54 | e.printStackTrace(); 55 | } 56 | //一行代码,执行每个服务的访问量总数统计 57 | ESAggDatas response = clientInterface.searchAgg("trace-*/_search",//从trace-开头的索引表中检索数据 58 | "termAgg", //配置在esmapper/testagg.xml中的dsl语句 59 | params, //dsl语句termAgg中需要的查询参数 60 | LongAggHit.class, //封装聚合统计中每个服务地址及服务访问量的地址 61 | "traces"); //term统计桶的名称,参见dsl语句 62 | List aggHitList = response.getAggDatas();//每个服务的访问量 63 | long totalSize = response.getTotalSize();//总访问量 64 | 65 | } 66 | 67 | @Test 68 | public void candicateAgg(){ 69 | ClientInterface clientInterface = ElasticSearchHelper.getConfigRestClientUtil("esmapper/testagg.xml"); 70 | Map params = null;//单值聚合统计条件参数 71 | //一行代码,执行服务基数统计 72 | //支持的数据封装类有:SingleIntegergAggHit,SingleLongAggHit,SingleDoubleAggHit,SingleFloatAggHit,SingleObjectAggHit 73 | ESAggDatas response = clientInterface.searchAgg("trace-*/_search","candicateAgg",params,SingleLongAggHit.class,"traces"); 74 | SingleLongAggHit aggHitList = response.getSingleAggData(); 75 | long value = aggHitList.getValue(); 76 | long totalSize = response.getTotalSize();//总访问量 77 | 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/aws/AWSClient.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.aws; 2 | /** 3 | * Copyright 2020 bboss 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 | 18 | /** 19 | *

Description:

20 | *

21 | *

Copyright (c) 2020

22 | * @Date 2020/5/13 17:35 23 | * @author biaoping.yin 24 | * @version 1.0 25 | */ 26 | public class AWSClient { 27 | public static void main(String[] args){ 28 | // final CredentialsProvider credentialsProvider = 29 | // new BasicCredentialsProvider(); 30 | // credentialsProvider.setCredentials(AuthScope.ANY, 31 | // new UsernamePasswordCredentials("elastic", "changeme")); 32 | // 33 | // AWSCredentials credentials = new BasicAWSCredentials("", ""); 34 | // AWS4Signer signer = new AWS4Signer(); 35 | // AWSCredentialsProvider awsCredentialsProvider = new AWSStaticCredentialsProvider(credentials); 36 | // signer.setServiceName("es"); 37 | // signer.setRegionName("us-east-1"); 38 | // 39 | //// final HttpRequestInterceptor interceptor = new AWSRequestSigningApacheInterceptor( 40 | //// "es", signer, awsCredentialsProvider); 41 | // HttpHost[] httpHosts = new HttpHost[0]; 42 | //// for (int i = 0; i 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 | 18 | import org.apache.http.Header; 19 | import org.apache.http.impl.client.HttpClientBuilder; 20 | import org.apache.http.message.BasicHeader; 21 | import org.frameworkset.spi.remote.http.ClientConfiguration; 22 | import org.frameworkset.spi.remote.http.callback.HttpClientBuilderCallback; 23 | 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | import java.util.concurrent.TimeUnit; 27 | 28 | /** 29 | *

Description:

30 | *

31 | *

Copyright (c) 2020

32 | * @Date 2020/5/14 10:27 33 | * @author biaoping.yin 34 | * @version 1.0 35 | */ 36 | public class HttpClientBuilderCallbackDemo implements HttpClientBuilderCallback { 37 | 38 | public HttpClientBuilder customizeHttpClient(HttpClientBuilder builder, ClientConfiguration clientConfiguration) { 39 | String user = clientConfiguration.getAuthAccount(); 40 | String password = clientConfiguration.getAuthPassword(); 41 | /** 42 | AWSCredentials credentials = new BasicAWSCredentials("", ""); 43 | AWS4Signer signer = new AWS4Signer(); 44 | AWSCredentialsProvider awsCredentialsProvider = new AWSStaticCredentialsProvider(credentials); 45 | signer.setServiceName("es"); 46 | signer.setRegionName("us-east-1"); 47 | 48 | HttpRequestInterceptor interceptor = new AWSRequestSigningApacheInterceptor( 49 | "es", signer, awsCredentialsProvider); 50 | builder.addInterceptorLast(interceptor); 51 | */ 52 | List
headerList = new ArrayList
(); 53 | Header header = new BasicHeader("test","asdfasdf"); 54 | builder.setDefaultHeaders(headerList); 55 | builder.evictIdleConnections(clientConfiguration.getTimeToLive(), TimeUnit.MILLISECONDS); 56 | return builder; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/badquery/TestBadQuery.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.badquery; 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 | 18 | import org.frameworkset.elasticsearch.ElasticSearchHelper; 19 | import org.frameworkset.elasticsearch.client.ClientInterface; 20 | import org.junit.Test; 21 | 22 | import java.sql.SQLException; 23 | import java.util.HashMap; 24 | import java.util.Map; 25 | 26 | /** 27 | *

Description:

28 | *

29 | *

Copyright (c) 2018

30 | * @Date 2018/12/30 20:39 31 | * @author biaoping.yin 32 | * @version 1.0 33 | */ 34 | public class TestBadQuery { 35 | private ClientInterface clientInterface = ElasticSearchHelper.getConfigRestClientUtil("esmapper/badquery.xml"); 36 | 37 | /** 38 | * 39 | * @throws SQLException 40 | */ 41 | @Test 42 | public void testBadQuery() throws SQLException 43 | { 44 | Map params = new HashMap(); 45 | 46 | 47 | String result = null; 48 | 49 | for(int i = 0; i < 6001; i ++){ 50 | //设置applicationName1和applicationName2两个变量的值 51 | params.put("applicationName1","blackcatdemo"+i); 52 | params.put("applicationName2","blackcatdemo"+i); 53 | result = clientInterface.executeRequest("demo/_search","testBadQuery",params); 54 | 55 | } 56 | } 57 | 58 | /** 59 | * 60 | * @throws SQLException 61 | */ 62 | @Test 63 | public void testGoodDsl() throws SQLException 64 | { 65 | Map params = new HashMap(); 66 | 67 | 68 | String result = null; 69 | 70 | for(int i = 0; i < 6001; i ++){ 71 | //设置applicationName1和applicationName2两个变量的值 72 | params.put("applicationName1","blackcatdemo"+i); 73 | params.put("applicationName2","blackcatdemo"+i); 74 | result = clientInterface.executeRequest("demo/_search","testGoodDsl",params); 75 | 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/bulkprocessor/PositionUrl.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.bulkprocessor; 2 | /** 3 | * Copyright 2008-2010 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 | 18 | 19 | import com.frameworkset.orm.annotation.PrimaryKey; 20 | 21 | import java.sql.Timestamp; 22 | 23 | /** 24 | *

Description:

25 | * 26 | * @author jun.xie 27 | * @version 1.0 28 | * @Date 2022/1/12 16:21 29 | */ 30 | public class PositionUrl implements java.io.Serializable { 31 | /** 32 | * 主键 33 | */ 34 | @PrimaryKey 35 | private String id; 36 | /** 37 | * 触点URL 38 | */ 39 | private String positionUrl; 40 | /** 41 | * 触点名称 42 | */ 43 | private String positionName; 44 | /** 45 | * 创建时间 46 | */ 47 | private Timestamp createtime; 48 | public PositionUrl() { 49 | } 50 | 51 | public String getId() { 52 | return id; 53 | } 54 | 55 | public void setId(String id) { 56 | this.id = id; 57 | } 58 | 59 | public String getPositionUrl() { 60 | return positionUrl; 61 | } 62 | 63 | public void setPositionUrl(String positionUrl) { 64 | this.positionUrl = positionUrl; 65 | } 66 | 67 | public String getPositionName() { 68 | return positionName; 69 | } 70 | 71 | public void setPositionName(String positionName) { 72 | this.positionName = positionName; 73 | } 74 | 75 | public Timestamp getCreatetime() { 76 | return createtime; 77 | } 78 | 79 | public void setCreatetime(Timestamp createtime) { 80 | this.createtime = createtime; 81 | } 82 | } -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/bulkprocessor/TestBulkProcessor7x_Size.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.bulkprocessor; 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 | 18 | import org.slf4j.Logger; 19 | import org.slf4j.LoggerFactory; 20 | 21 | /** 22 | *

Description: for elasticsearch 7x

23 | *

24 | *

Copyright (c) 2018

25 | * @Date 2019/12/8 9:57 26 | * @author biaoping.yin 27 | * @version 1.0 28 | */ 29 | public class TestBulkProcessor7x_Size { 30 | private static Logger logger = LoggerFactory.getLogger(TestBulkProcessor7x_Size.class); 31 | 32 | public static void main(String[] args){ 33 | TestBulkProcessor7x testBulkProcessor = new TestBulkProcessor7x(); 34 | //设置批量记录占用内存最大值,以字节为单位,达到最大值时,执行一次bulk操作 35 | // 可以根据实际情况调整maxMemSize参数,如果不设置maxMemSize,则按照按批处理数据记录数BulkSizes来判别是否执行执行一次bulk操作 36 | //maxMemSize参数默认值为0,不起作用,只有>0才起作用 37 | 38 | testBulkProcessor.buildBulkProcessor(0,1000);//禁用maxMemSize参数 39 | // testBulkProcessor.buildLogBulkProcessor(); 40 | testBulkProcessor.testBulkDatas(); 41 | 42 | // testBulkProcessor.shutdown(false);//调用shutDown停止方法后,BulkProcessor不会接收新的请求,但是会处理完所有已经进入bulk队列的数据 43 | 44 | 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/bulkprocessor/TestObject.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.bulkprocessor; 2 | /** 3 | * Copyright 2020 bboss 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 | 18 | /** 19 | *

Description:

20 | *

21 | *

Copyright (c) 2020

22 | * @Date 2020/3/3 17:12 23 | * @author biaoping.yin 24 | * @version 1.0 25 | */ 26 | public class TestObject { 27 | private String id; 28 | private String name; 29 | 30 | public String getId() { 31 | return id; 32 | } 33 | 34 | public void setId(String id) { 35 | this.id = id; 36 | } 37 | 38 | public String getName() { 39 | return name; 40 | } 41 | 42 | public void setName(String name) { 43 | this.name = name; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/crud/DeleteUdateByQueryTest.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.crud;/* 2 | * Copyright 2008 biaoping.yin 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 | 17 | import org.bboss.elasticsearchtest.byquery.DeleteUdateByQuery; 18 | import org.junit.Test; 19 | 20 | import java.text.ParseException; 21 | 22 | public class DeleteUdateByQueryTest { 23 | 24 | @Test 25 | public void testDeleteByQuery() throws ParseException { 26 | DeleteUdateByQuery deleteUdateByQuery = new DeleteUdateByQuery(); 27 | deleteUdateByQuery.initIndiceAndData();//初始化索引表和测试数据 28 | deleteUdateByQuery.deleteByQuery();//执行deleteByquery 29 | } 30 | @Test 31 | public void testUpdateByQuery() throws ParseException { 32 | DeleteUdateByQuery deleteUdateByQuery = new DeleteUdateByQuery(); 33 | deleteUdateByQuery.initIndiceAndData();//初始化索引表和测试数据 34 | deleteUdateByQuery.simpleUpdateByQuery(); 35 | deleteUdateByQuery.updateByQueryWithCondition(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/crud/DocumentSearchAfterTest.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.crud;/* 2 | * Copyright 2008 biaoping.yin 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 | 17 | import org.bboss.elasticsearchtest.searchafter.DocumentSearchAfter; 18 | import org.junit.Test; 19 | 20 | import java.text.ParseException; 21 | 22 | public class DocumentSearchAfterTest { 23 | 24 | @Test 25 | public void testSeachAfter() throws ParseException { 26 | DocumentSearchAfter documentSearchAfter = new DocumentSearchAfter(); 27 | documentSearchAfter.initIndiceAndData();//创建索引表并导入searchAfter分页测试数据 28 | documentSearchAfter.doSeachAfter();//执行searchAfter分页操作 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/crud/TestSearchGuard.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.crud; 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 | 18 | import org.frameworkset.elasticsearch.ElasticSearchHelper; 19 | import org.frameworkset.elasticsearch.client.ClientInterface; 20 | import org.frameworkset.elasticsearch.entity.ESDatas; 21 | import org.frameworkset.elasticsearch.entity.MetaMap; 22 | 23 | /** 24 | *

Description:

25 | *

26 | *

Copyright (c) 2018

27 | * @Date 2020/1/8 18:00 28 | * @author biaoping.yin 29 | * @version 1.0 30 | */ 31 | public class TestSearchGuard { 32 | public static void main(String[] args){ 33 | //创建加载配置文件的客户端工具,用来检索文档,单实例多线程安全 34 | ClientInterface clientUtil = ElasticSearchHelper.getRestClientUtil(); 35 | ESDatas datas = clientUtil.searchAll("yaxin-agentevent-*", MetaMap.class); 36 | System.out.println(datas.getTotalSize()); 37 | // yaxin-agentevent-20200108 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/crud/TestSlowDslCallback.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.crud; 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 | 18 | import com.frameworkset.util.SimpleStringUtil; 19 | import org.frameworkset.elasticsearch.client.LogDslCallback; 20 | import org.frameworkset.elasticsearch.entity.LogDsl; 21 | 22 | /** 23 | *

Description:

24 | *

25 | *

Copyright (c) 2018

26 | * @Date 2019/11/13 14:07 27 | * @author biaoping.yin 28 | * @version 1.0 29 | */ 30 | public class TestSlowDslCallback implements LogDslCallback { 31 | public void logDsl(LogDsl slowDsl) { 32 | System.out.println(SimpleStringUtil.object2json(slowDsl)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/custominit/CustormInitAndBoot1.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.custominit; 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 | 18 | import org.frameworkset.elasticsearch.ElasticSearchHelper; 19 | import org.frameworkset.elasticsearch.boot.ElasticSearchBoot; 20 | import org.frameworkset.elasticsearch.client.ClientInterface; 21 | import org.junit.Test; 22 | 23 | import java.util.HashMap; 24 | import java.util.Map; 25 | 26 | /** 27 | *

Description:

28 | *

29 | *

Copyright (c) 2018

30 | * @Date 2019/5/30 15:23 31 | * @author biaoping.yin 32 | * @version 1.0 33 | */ 34 | public class CustormInitAndBoot1 { 35 | private void init(){ 36 | Map properties = new HashMap(); 37 | //认证账号和口令配置,如果启用了安全认证才需要,支持xpack和searchguard 38 | properties.put("elasticsearch.serverNames","default"); 39 | properties.put("elasticUser","elastic"); 40 | properties.put("elasticPassword","changeme"); 41 | //es服务器地址和端口,多个用逗号分隔 42 | properties.put("elasticsearch.rest.hostNames","es.iisc.com:9200"); 43 | //是否在控制台打印dsl语句,log4j组件日志级别为INFO或者DEBUG 44 | properties.put("elasticsearch.showTemplate","true"); 45 | //集群节点自动发现 46 | properties.put("elasticsearch.discoverHost","false"); 47 | properties.put("http.timeoutSocket","60000"); 48 | properties.put("http.timeoutConnection","40000"); 49 | properties.put("http.connectionRequestTimeout","70000"); 50 | 51 | ElasticSearchBoot.boot(properties); 52 | } 53 | /** 54 | * 初始化一个Elasticsearch数据源 55 | */ 56 | @Test 57 | public void testSingleESDatasourceBoot(){ 58 | init(); 59 | 60 | Thread t = new Thread(new Runnable() { 61 | @Override 62 | public void run() { 63 | try { 64 | Thread.sleep(10000L); 65 | } catch (InterruptedException e) { 66 | e.printStackTrace(); 67 | } 68 | ElasticSearchHelper.stopElasticsearch("default"); 69 | try { 70 | Thread.sleep(10000L); 71 | } catch (InterruptedException e) { 72 | e.printStackTrace(); 73 | } 74 | init(); 75 | } 76 | }); 77 | t.start(); 78 | 79 | ClientInterface clientUtil = ElasticSearchHelper.getRestClientUtil(); 80 | while (true) { 81 | //获取ES版本信息 82 | try { 83 | Thread.sleep(1000L); 84 | 85 | // 清除DNS缓存 86 | String result = clientUtil.executeHttp("/?pretty", ClientInterface.HTTP_GET); 87 | 88 | } 89 | catch (Exception e){ 90 | e.printStackTrace(); 91 | } 92 | } 93 | 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/db2es/CustomObject.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.db2es; 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 | 18 | /** 19 | *

Description:

20 | *

21 | *

Copyright (c) 2018

22 | * @Date 2018/9/4 10:37 23 | * @author biaoping.yin 24 | * @version 1.0 25 | */ 26 | public class CustomObject { 27 | private String title; 28 | private String subtitle; 29 | private String author; 30 | private int[] ids; 31 | 32 | public String getTitle() { 33 | return title; 34 | } 35 | 36 | public void setTitle(String title) { 37 | this.title = title; 38 | } 39 | 40 | public String getSubtitle() { 41 | return subtitle; 42 | } 43 | 44 | public void setSubtitle(String subtitle) { 45 | this.subtitle = subtitle; 46 | } 47 | 48 | public String getAuthor() { 49 | return author; 50 | } 51 | 52 | public void setAuthor(String author) { 53 | this.author = author; 54 | } 55 | 56 | public int[] getIds() { 57 | return ids; 58 | } 59 | 60 | public void setIds(int[] ids) { 61 | this.ids = ids; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/db2es/TestObject.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.db2es; 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 | 18 | /** 19 | *

Description:

20 | *

21 | *

Copyright (c) 2018

22 | * @Date 2018/9/3 21:38 23 | * @author biaoping.yin 24 | * @version 1.0 25 | */ 26 | public class TestObject { 27 | private String id; 28 | 29 | public String getId() { 30 | return id; 31 | } 32 | 33 | public void setId(String id) { 34 | this.id = id; 35 | } 36 | 37 | public String getName() { 38 | return name; 39 | } 40 | 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | 45 | private String name; 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/dsl/TestPianduan.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.dsl; 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 | 18 | import org.frameworkset.elasticsearch.client.ConfigHolder; 19 | import org.frameworkset.elasticsearch.template.ConfigDSLUtil; 20 | import org.frameworkset.elasticsearch.template.ESTemplateHelper; 21 | import org.junit.Test; 22 | 23 | import java.util.HashMap; 24 | import java.util.Map; 25 | 26 | /** 27 | *

Description:

28 | *

29 | *

Copyright (c) 2018

30 | * @Date 2019/3/15 13:08 31 | * @author biaoping.yin 32 | * @version 1.0 33 | */ 34 | public class TestPianduan { 35 | @Test 36 | public void testoutPianduan(){ 37 | Map params = new HashMap(); 38 | //设置参数 39 | params.put("cityId","10002"); 40 | params.put("titleId",new String[]{"5", 41 | "6", 42 | "4", 43 | "9"}); 44 | params.put("deptId1","65"); 45 | params.put("deptId2","65"); 46 | params.put("deptId3","65"); 47 | //设置size,最多返回1000条记录 48 | params.put("size",1000); 49 | //加载配置文件中的dsl信息,解析dsl语句dynamicInnerDsl 50 | ConfigHolder configHolder = new ConfigHolder(); 51 | ConfigDSLUtil esUtil = configHolder.getConfigDSLUtil("esmapper/outpianduanref.xml"); 52 | String parseResult = ESTemplateHelper.evalTemplate(esUtil,"testoutPianduan",params); 53 | //打印解析结果 54 | System.out.println(parseResult); 55 | 56 | } 57 | 58 | @Test 59 | public void testinnerPianduan(){ 60 | Map params = new HashMap(); 61 | //设置参数 62 | params.put("cityId","sss/+\"sss"); 63 | params.put("titleId",new String[]{"5", 64 | "6", 65 | "4", 66 | "9"}); 67 | params.put("deptId1","65"); 68 | params.put("deptId2","65"); 69 | params.put("deptId3","65"); 70 | //设置size,最多返回1000条记录 71 | params.put("size",1000); 72 | //加载配置文件中的dsl信息,解析dsl语句dynamicInnerDsl 73 | ConfigHolder configHolder = new ConfigHolder(); 74 | ConfigDSLUtil esUtil = configHolder.getConfigDSLUtil("esmapper/outpianduanref.xml"); 75 | String parseResult = ESTemplateHelper.evalTemplate(esUtil,"testinnerPianduan",params); 76 | //打印解析结果 77 | System.out.println(parseResult); 78 | 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/forcemerge/ForceMergeTest.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.forcemerge; 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 | 18 | import org.frameworkset.elasticsearch.ElasticSearchHelper; 19 | import org.frameworkset.elasticsearch.client.ClientInterface; 20 | import org.frameworkset.elasticsearch.entity.MergeOption; 21 | import org.junit.Test; 22 | 23 | /** 24 | *

Description:

25 | *

26 | *

Copyright (c) 2018

27 | * @Date 2019/7/7 16:11 28 | * @author biaoping.yin 29 | * @version 1.0 30 | */ 31 | public class ForceMergeTest { 32 | @Test 33 | public void testMerge(){ 34 | ClientInterface clientInterface = ElasticSearchHelper.getRestClientUtil(); 35 | 36 | clientInterface.forcemerge();//强制合并所以索引的segment 37 | 38 | MergeOption mergeOption = new MergeOption(); 39 | mergeOption.setFlush(true); 40 | mergeOption.setMaxnumSegments(1); 41 | mergeOption.setOnlyExpungeDeletes(false); 42 | 43 | clientInterface.forcemerge(mergeOption );//强制合并所以索引的segment,并指定合并参数选项 44 | 45 | clientInterface.forcemerge("indice1");//强制合并索引indice1的segment 46 | 47 | clientInterface.forcemerge("indice1,indice2");//强制合并索引indice1和indice2的segment 48 | 49 | mergeOption = new MergeOption(); 50 | mergeOption.setFlush(false); 51 | mergeOption.setMaxnumSegments(1); 52 | mergeOption.setOnlyExpungeDeletes(false); 53 | 54 | clientInterface.forcemerge("indice1",mergeOption );//强制合并索引indice1的segment,并指定合并参数选项 55 | 56 | clientInterface.forcemerge("indice1,indice2",mergeOption );//强制合并索引indice1和indice2的segment,并指定合并参数选项 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/index/AliasTest.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.index; 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 | 18 | import org.frameworkset.elasticsearch.ElasticSearchHelper; 19 | import org.frameworkset.elasticsearch.client.ClientInterface; 20 | import org.junit.Test; 21 | 22 | /** 23 | *

Description:

24 | *

25 | *

Copyright (c) 2018

26 | * @Date 2018/7/25 22:59 27 | * @author biaoping.yin 28 | * @version 1.0 29 | */ 30 | public class AliasTest { 31 | @Test 32 | public void testAddAlias(){ 33 | ClientInterface clientInterface = ElasticSearchHelper.getRestClientUtil(); 34 | String response = clientInterface.addAlias("demo","demoalias"); 35 | System.out.println(response); 36 | response = clientInterface.getIndexMapping("demoalias",true); 37 | System.out.println(response); 38 | long count = clientInterface.countAll("demoalias"); 39 | System.out.println(count); 40 | } 41 | 42 | @Test 43 | public void testRemoveAlias(){ 44 | ClientInterface clientInterface = ElasticSearchHelper.getRestClientUtil(); 45 | String response = clientInterface.removeAlias("demo","demoalias"); 46 | System.out.println(response); 47 | try { 48 | response = clientInterface.getIndexMapping("demoalias", true); 49 | System.out.println(response); 50 | } 51 | catch (Exception e){ 52 | e.printStackTrace(); 53 | } 54 | long count = clientInterface.countAll("demo"); 55 | System.out.println(count); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/index/GetAllIndices.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.index; 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 | 18 | import org.frameworkset.elasticsearch.ElasticSearchHelper; 19 | import org.frameworkset.elasticsearch.client.ClientInterface; 20 | import org.frameworkset.elasticsearch.entity.ESIndice; 21 | import org.frameworkset.elasticsearch.entity.IndexField; 22 | import org.junit.Test; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | *

Description:

28 | *

29 | *

Copyright (c) 2018

30 | * @Date 2019/3/21 11:57 31 | * @author biaoping.yin 32 | * @version 1.0 33 | */ 34 | public class GetAllIndices { 35 | @Test 36 | public void testGetAllIndices(){ 37 | ClientInterface clientInterface = ElasticSearchHelper.getRestClientUtil(); 38 | List indices = clientInterface.getIndexes(); 39 | } 40 | @Test 41 | public void testGetIndice(){ 42 | ClientInterface clientInterface = ElasticSearchHelper.getRestClientUtil(); 43 | List indexFields = clientInterface.getIndexMappingFields("demo","demo"); 44 | System.out.println(indexFields.size()); 45 | } 46 | @Test 47 | public void testIndiceCloseOpen(){ 48 | ClientInterface clientInterface = ElasticSearchHelper.getRestClientUtil(); 49 | clientInterface.closeIndex("demo");//关闭索引 50 | List indices = clientInterface.getIndexes(); 51 | List indexFields = clientInterface.getIndexMappingFields("demo","demo"); 52 | clientInterface.openIndex("demo");//打开索引 53 | indices = clientInterface.getIndexes(); 54 | clientInterface.openIndex("demo");//打开索引 55 | 56 | } 57 | 58 | @Test 59 | public void testIndiceGet(){ 60 | ClientInterface clientInterface = ElasticSearchHelper.getRestClientUtil(); 61 | 62 | List indices = clientInterface.getIndexes(); 63 | List indicesD = clientInterface.getIndexes("d*"); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/index/ReindexTest.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.index; 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 | 18 | import org.frameworkset.elasticsearch.ElasticSearchHelper; 19 | import org.frameworkset.elasticsearch.client.ClientInterface; 20 | import org.junit.Test; 21 | 22 | /** 23 | *

Description:

24 | *

25 | *

Copyright (c) 2018

26 | * @Date 2018/7/25 22:53 27 | * @author biaoping.yin 28 | * @version 1.0 29 | */ 30 | public class ReindexTest { 31 | @Test 32 | public void reIndex(){ 33 | ClientInterface clientInterface = ElasticSearchHelper.getRestClientUtil(); 34 | String response = clientInterface.reindex("demo","newdemo"); 35 | System.out.println(response); 36 | response = clientInterface.getIndexMapping("newdemo",true); 37 | System.out.println(response); 38 | long count = clientInterface.countAll("newdemo"); 39 | System.out.println(count); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/index/UpdateIndiceMapping.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.index; 2 | /** 3 | * Copyright 2020 bboss 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 | 18 | import org.frameworkset.elasticsearch.ElasticSearchHelper; 19 | import org.frameworkset.elasticsearch.client.ClientInterface; 20 | import org.junit.Test; 21 | 22 | /** 23 | *

Description:

24 | *

25 | *

Copyright (c) 2020

26 | * @Date 2020/6/1 9:56 27 | * @author biaoping.yin 28 | * @version 1.0 29 | */ 30 | public class UpdateIndiceMapping { 31 | @Test 32 | public void testUpdateIndiceMapping(){ 33 | ClientInterface clientInterface = ElasticSearchHelper.getConfigRestClientUtil("esmapper/demo7.xml"); 34 | if(!clientInterface.isVersionUpper7()) 35 | 36 | clientInterface.updateIndiceMapping("/demo/_doc/_mapping","updateDemoIndice"); 37 | else{ 38 | clientInterface.updateIndiceMapping("/demo/_mapping","updateDemoIndice");//无需指定type 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/jointype/Answer.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.jointype; 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 | 18 | import com.fasterxml.jackson.annotation.JsonFormat; 19 | import com.fasterxml.jackson.annotation.JsonProperty; 20 | import com.frameworkset.orm.annotation.Column; 21 | import com.frameworkset.orm.annotation.ESId; 22 | import com.frameworkset.orm.annotation.ESRouting; 23 | import org.frameworkset.elasticsearch.entity.ESBaseData; 24 | import org.frameworkset.elasticsearch.entity.JoinSon; 25 | 26 | import java.util.Date; 27 | 28 | /** 29 | *

Description:

30 | *

31 | *

Copyright (c) 2018

32 | * @Date 2018/11/22 16:15 33 | * @author biaoping.yin 34 | * @version 1.0 35 | */ 36 | public class Answer extends ESBaseData { 37 | @ESId(persistent = true) 38 | private String aid; 39 | private String name; 40 | private String content; 41 | private String person; 42 | 43 | private int datatype; 44 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 45 | @Column(dataformat = "yyyy-MM-dd HH:mm:ss") 46 | @JsonProperty("created_date") 47 | private Date createdDate; 48 | @JsonProperty("question_join") 49 | private JoinSon questionJoin; 50 | @ESRouting 51 | private String routingId; 52 | 53 | public String getName() { 54 | return name; 55 | } 56 | 57 | public void setName(String name) { 58 | this.name = name; 59 | } 60 | 61 | public String getContent() { 62 | return content; 63 | } 64 | 65 | public void setContent(String content) { 66 | this.content = content; 67 | } 68 | 69 | public String getPerson() { 70 | return person; 71 | } 72 | 73 | public void setPerson(String person) { 74 | this.person = person; 75 | } 76 | 77 | public int getDatatype() { 78 | return datatype; 79 | } 80 | 81 | public void setDatatype(int datatype) { 82 | this.datatype = datatype; 83 | } 84 | 85 | public Date getCreatedDate() { 86 | return createdDate; 87 | } 88 | 89 | public void setCreatedDate(Date createdDate) { 90 | this.createdDate = createdDate; 91 | } 92 | 93 | public JoinSon getQuestionJoin() { 94 | return questionJoin; 95 | } 96 | 97 | public void setQuestionJoin(JoinSon questionJoin) { 98 | this.questionJoin = questionJoin; 99 | } 100 | 101 | 102 | 103 | public String getRoutingId() { 104 | return routingId; 105 | } 106 | 107 | public void setRoutingId(String routingId) { 108 | this.routingId = routingId; 109 | } 110 | 111 | public String getAid() { 112 | return aid; 113 | } 114 | 115 | public void setAid(String aid) { 116 | this.aid = aid; 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/jointype/Comment.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.jointype; 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 | 18 | import com.fasterxml.jackson.annotation.JsonFormat; 19 | import com.fasterxml.jackson.annotation.JsonProperty; 20 | import com.frameworkset.orm.annotation.Column; 21 | import com.frameworkset.orm.annotation.ESId; 22 | import com.frameworkset.orm.annotation.ESRouting; 23 | import org.frameworkset.elasticsearch.entity.ESBaseData; 24 | import org.frameworkset.elasticsearch.entity.JoinSon; 25 | 26 | import java.util.Date; 27 | 28 | /** 29 | *

Description:

30 | *

31 | *

Copyright (c) 2018

32 | * @Date 2018/11/22 16:15 33 | * @author biaoping.yin 34 | * @version 1.0 35 | */ 36 | public class Comment extends ESBaseData { 37 | @ESId(persistent = true) 38 | private String cid; 39 | private String name; 40 | private String content; 41 | private String person; 42 | 43 | private int datatype; 44 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 45 | @Column(dataformat = "yyyy-MM-dd HH:mm:ss") 46 | @JsonProperty("created_date") 47 | private Date createdDate; 48 | @JsonProperty("question_join") 49 | private JoinSon questionJoin; 50 | @ESRouting 51 | private String routingId; 52 | 53 | public String getName() { 54 | return name; 55 | } 56 | 57 | public void setName(String name) { 58 | this.name = name; 59 | } 60 | 61 | public String getContent() { 62 | return content; 63 | } 64 | 65 | public void setContent(String content) { 66 | this.content = content; 67 | } 68 | 69 | public String getPerson() { 70 | return person; 71 | } 72 | 73 | public void setPerson(String person) { 74 | this.person = person; 75 | } 76 | 77 | public int getDatatype() { 78 | return datatype; 79 | } 80 | 81 | public void setDatatype(int datatype) { 82 | this.datatype = datatype; 83 | } 84 | 85 | public Date getCreatedDate() { 86 | return createdDate; 87 | } 88 | 89 | public void setCreatedDate(Date createdDate) { 90 | this.createdDate = createdDate; 91 | } 92 | 93 | public JoinSon getQuestionJoin() { 94 | return questionJoin; 95 | } 96 | 97 | public void setQuestionJoin(JoinSon questionJoin) { 98 | this.questionJoin = questionJoin; 99 | } 100 | 101 | 102 | public String getCid() { 103 | return cid; 104 | } 105 | 106 | public void setCid(String cid) { 107 | this.cid = cid; 108 | } 109 | 110 | public String getRoutingId() { 111 | return routingId; 112 | } 113 | 114 | public void setRoutingId(String routingId) { 115 | this.routingId = routingId; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/jointype/Question.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.jointype; 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 | 18 | import com.fasterxml.jackson.annotation.JsonFormat; 19 | import com.fasterxml.jackson.annotation.JsonProperty; 20 | import com.frameworkset.orm.annotation.Column; 21 | import com.frameworkset.orm.annotation.ESId; 22 | import com.frameworkset.orm.annotation.ESRouting; 23 | import org.frameworkset.elasticsearch.entity.ESBaseData; 24 | import org.frameworkset.elasticsearch.entity.JoinSon; 25 | 26 | import java.util.Date; 27 | 28 | /** 29 | *

Description:

30 | *

31 | *

Copyright (c) 2018

32 | * @Date 2018/11/22 16:10 33 | * @author biaoping.yin 34 | * @version 1.0 35 | */ 36 | public class Question extends ESBaseData { 37 | @ESId(persistent = true) 38 | private String qid; 39 | private String name; 40 | private String content; 41 | private String person; 42 | 43 | private int datatype; 44 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 45 | @Column(dataformat = "yyyy-MM-dd HH:mm:ss") 46 | @JsonProperty("created_date") 47 | private Date createdDate; 48 | @JsonProperty("question_join") 49 | private JoinSon questionJoin; 50 | @ESRouting 51 | private String routingId; 52 | 53 | public String getName() { 54 | return name; 55 | } 56 | 57 | public void setName(String name) { 58 | this.name = name; 59 | } 60 | 61 | public String getContent() { 62 | return content; 63 | } 64 | 65 | public void setContent(String content) { 66 | this.content = content; 67 | } 68 | 69 | public String getPerson() { 70 | return person; 71 | } 72 | 73 | public void setPerson(String person) { 74 | this.person = person; 75 | } 76 | 77 | public int getDatatype() { 78 | return datatype; 79 | } 80 | 81 | public void setDatatype(int datatype) { 82 | this.datatype = datatype; 83 | } 84 | 85 | public Date getCreatedDate() { 86 | return createdDate; 87 | } 88 | 89 | public void setCreatedDate(Date createdDate) { 90 | this.createdDate = createdDate; 91 | } 92 | 93 | public JoinSon getQuestionJoin() { 94 | return questionJoin; 95 | } 96 | 97 | public void setQuestionJoin(JoinSon questionJoin) { 98 | this.questionJoin = questionJoin; 99 | } 100 | 101 | public String getQid() { 102 | return qid; 103 | } 104 | 105 | public void setQid(String qid) { 106 | this.qid = qid; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/license/ImportLicense.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.license; 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 | 18 | import org.frameworkset.elasticsearch.ElasticSearchHelper; 19 | import org.frameworkset.elasticsearch.client.ClientInterface; 20 | import org.frameworkset.elasticsearch.client.ClientUtil; 21 | import org.junit.Test; 22 | 23 | /** 24 | *

Description: import x-pack license

25 | *

26 | *

Copyright (c) 2018

27 | * @Date 2018/8/18 23:33 28 | * @author biaoping.yin 29 | * @version 1.0 30 | */ 31 | public class ImportLicense { 32 | @Test 33 | public void testLicense(){ 34 | ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/license.xml"); 35 | 36 | /** 37 | * Elasticsearch 6.x ,7.x导入license 38 | */ 39 | // String ttt = clientUtil.executeHttp("_xpack/license?acknowledge=true","license",ClientUtil.HTTP_PUT); 40 | /** 41 | * Elasticsearch 8.x导入license 42 | */ 43 | String ttt = clientUtil.executeHttp("_license?acknowledge=true","license",ClientUtil.HTTP_PUT); 44 | 45 | System.out.println(ttt); 46 | // ttt = clientUtil.createTempate("tracesql_template","traceSQLTemplate"); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/mapping/MappingTest.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.mapping; 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 | 18 | import org.frameworkset.elasticsearch.ElasticSearchHelper; 19 | import org.frameworkset.elasticsearch.client.ClientInterface; 20 | import org.frameworkset.elasticsearch.entity.ESIndice; 21 | import org.junit.Test; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | *

Description:

27 | *

28 | *

Copyright (c) 2018

29 | * @Date 2018/11/13 9:55 30 | * @author biaoping.yin 31 | * @version 1.0 32 | */ 33 | public class MappingTest { 34 | @Test 35 | public void createMapping(){ 36 | ClientInterface clientInterface = ElasticSearchHelper.getConfigRestClientUtil("esmapper/arryaymapping.xml"); 37 | //从配置文件esmapper/arryaymapping.xml中获取mapping结构,并创建hostagentinfo结构 38 | String result = clientInterface.createIndiceMapping("hostagentinfotest","hostAgentInfoIndice"); 39 | System.out.println(result); 40 | } 41 | 42 | @Test 43 | public void deleteMapping(){ 44 | ClientInterface clientInterface = ElasticSearchHelper.getRestClientUtil(); 45 | //删除mapping结构 46 | String result = clientInterface.dropIndice("hostagentinfotest"); 47 | System.out.println(result); 48 | } 49 | 50 | @Test 51 | public void getMapping(){ 52 | ClientInterface clientInterface = ElasticSearchHelper.getRestClientUtil(); 53 | //获取hostagentinfo的mapping结构 54 | String mapping = clientInterface.getIndexMapping("hostagentinfotest"); 55 | System.out.println(mapping); 56 | } 57 | 58 | @Test 59 | public void getAllMapping(){ 60 | //获取所有的indice mappings 61 | ClientInterface clientInterface = ElasticSearchHelper.getRestClientUtil(); 62 | List mapping = clientInterface.getIndexes(); 63 | System.out.println(mapping); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/parentchild/Company.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.parentchild;/* 2 | * Copyright 2008 biaoping.yin 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 | 17 | import com.frameworkset.orm.annotation.ESId; 18 | import org.frameworkset.elasticsearch.entity.ESBaseData; 19 | 20 | public class Company extends ESBaseData { 21 | private String name; 22 | /** 23 | * 将companyId作为索引_id的值 24 | */ 25 | @ESId(readSet = true) 26 | private String companyId; 27 | private String city; 28 | private String country; 29 | 30 | public String getName() { 31 | return name; 32 | } 33 | 34 | public void setName(String name) { 35 | this.name = name; 36 | } 37 | 38 | public String getCity() { 39 | return city; 40 | } 41 | 42 | public void setCity(String city) { 43 | this.city = city; 44 | } 45 | 46 | public String getCountry() { 47 | return country; 48 | } 49 | 50 | public void setCountry(String country) { 51 | this.country = country; 52 | } 53 | 54 | public String getCompanyId() { 55 | return companyId; 56 | } 57 | 58 | public void setCompanyId(String companyId) { 59 | this.companyId = companyId; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/parentchild/Employee.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.parentchild;/* 2 | * Copyright 2008 biaoping.yin 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 | 17 | import com.fasterxml.jackson.annotation.JsonFormat; 18 | import com.frameworkset.orm.annotation.Column; 19 | import com.frameworkset.orm.annotation.ESId; 20 | import com.frameworkset.orm.annotation.ESParentId; 21 | import org.frameworkset.elasticsearch.entity.ESBaseData; 22 | 23 | import java.util.Date; 24 | 25 | public class Employee extends ESBaseData { 26 | /** 27 | * 通过ESId注解将employeeId指定为雇员的文档_id 28 | */ 29 | @ESId 30 | private int employeeId; 31 | /** 32 | * 通过ESParentId注解将companyId指定为雇员的parent属性,对应Company中的文档_id的值 33 | */ 34 | @ESParentId 35 | private String companyId; 36 | private String name; 37 | @JsonFormat(pattern = "yyyy-MM-dd") 38 | @Column(dataformat = "yyyy-MM-dd") 39 | private Date birthday; 40 | private String hobby; 41 | 42 | 43 | public String getName() { 44 | return name; 45 | } 46 | 47 | public void setName(String name) { 48 | this.name = name; 49 | } 50 | 51 | public Date getBirthday() { 52 | return birthday; 53 | } 54 | 55 | public void setBirthday(Date birthday) { 56 | this.birthday = birthday; 57 | } 58 | 59 | public String getHobby() { 60 | return hobby; 61 | } 62 | 63 | public void setHobby(String hobby) { 64 | this.hobby = hobby; 65 | } 66 | 67 | public int getEmployeeId() { 68 | return employeeId; 69 | } 70 | 71 | public void setEmployeeId(int employeeId) { 72 | this.employeeId = employeeId; 73 | } 74 | 75 | 76 | 77 | public String getCompanyId() { 78 | return companyId; 79 | } 80 | 81 | public void setCompanyId(String companyId) { 82 | this.companyId = companyId; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/query/MoreLikeThis.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.query; 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 | 18 | import org.frameworkset.elasticsearch.ElasticSearchHelper; 19 | import org.frameworkset.elasticsearch.client.ClientInterface; 20 | import org.frameworkset.elasticsearch.entity.ESDatas; 21 | import org.junit.Test; 22 | 23 | import java.util.List; 24 | import java.util.Map; 25 | 26 | /** 27 | *

Description: https://www.elastic.co/guide/en/elasticsearch/reference/7.4/query-dsl-mlt-query.html 28 | *

29 | *

30 | *

Copyright (c) 2018

31 | * @Date 2019/12/1 11:30 32 | * @author biaoping.yin 33 | * @version 1.0 34 | */ 35 | public class MoreLikeThis { 36 | @Test 37 | public void testMoreLikeThis(){ 38 | /** 39 | * { 40 | * "query": { 41 | * "more_like_this" : { 42 | * "fields" : ["title", "description"], 43 | * "like" : "Once upon a time", 44 | * "min_term_freq" : 1, 45 | * "max_query_terms" : 12 46 | * } 47 | * } 48 | * } 49 | */ 50 | ClientInterface clientInterface = ElasticSearchHelper.getConfigRestClientUtil("esmapper/morelikethis.xml"); 51 | // O/R mapping方式检索,将结果解析为对象类型 52 | ESDatas esDatas = clientInterface.searchList("dbdemo/_search","moreLikeThisDsl", Map.class); 53 | List datas = esDatas.getDatas(); 54 | long totalSize = esDatas.getTotalSize(); 55 | System.out.println(datas); 56 | // 原始报文方式检索,直接返回json报文 57 | String json = clientInterface.executeHttp("dbdemo/_search","moreLikeThisDsl", Map.class,ClientInterface.HTTP_POST); 58 | System.out.println(json); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/query/TestQuery.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.query; 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 | 18 | import org.frameworkset.elasticsearch.ElasticSearchHelper; 19 | import org.frameworkset.elasticsearch.client.ClientInterface; 20 | import org.frameworkset.elasticsearch.entity.ESDatas; 21 | import org.junit.Test; 22 | 23 | import java.util.Map; 24 | 25 | /** 26 | *

Description:

27 | *

28 | *

Copyright (c) 2018

29 | * @Date 2019/7/13 12:05 30 | * @author biaoping.yin 31 | * @version 1.0 32 | */ 33 | public class TestQuery { 34 | 35 | @Test 36 | public void testQueryObject(){ 37 | //batchUuid:b13e998a-78c7-48f5-b067-d4b6d0b044a4 38 | 39 | ClientInterface clientInterface = ElasticSearchHelper.getRestClientUtil(); 40 | Map data = clientInterface.searchObject("terminalcontent-*/_search?q=batchUuid:b13e998a-78c7-48f5-b067-d4b6d0b044a4&size=1&terminate_after=1",Map.class); 41 | System.out.println(data); 42 | } 43 | 44 | @Test 45 | public void testQueryList(){ 46 | //batchUuid:b13e998a-78c7-48f5-b067-d4b6d0b044a4 47 | 48 | ClientInterface clientInterface = ElasticSearchHelper.getRestClientUtil(); 49 | ESDatas data = clientInterface.searchList("terminalcontent-*/_search?q=requestType:httprequest",Map.class); 50 | System.out.println(data.getDatas()); 51 | System.out.println(data.getTotalSize()); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/score/UserInfo.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.score; 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 | 18 | import com.frameworkset.orm.annotation.ESId; 19 | import org.frameworkset.elasticsearch.entity.ESBaseData; 20 | 21 | /** 22 | *

Description:

23 | *

24 | *

Copyright (c) 2018

25 | * @Date 2019/3/16 14:19 26 | * @author biaoping.yin 27 | * @version 1.0 28 | */ 29 | public class UserInfo extends ESBaseData { 30 | @ESId(readSet = true) 31 | private String userId; 32 | private String name; 33 | 34 | public String getName() { 35 | return name; 36 | } 37 | 38 | public void setName(String name) { 39 | this.name = name; 40 | } 41 | 42 | public String getUserId() { 43 | return userId; 44 | } 45 | 46 | public void setUserId(String userId) { 47 | this.userId = userId; 48 | } 49 | public String toString(){ 50 | StringBuilder ret = new StringBuilder(); 51 | ret.append("{\"name\":").append("\"").append(this.getName()).append("\","); 52 | ret.append("\"userId\":").append("\"").append(this.getUserId()).append("\","); 53 | ret.append("\"score\":").append(this.getScore()).append("}"); 54 | ret.append("\n"); 55 | return ret.toString(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/script/ScriptImpl7Test.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.script;/* 2 | * Copyright 2008 biaoping.yin 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 | 17 | import com.frameworkset.util.SimpleStringUtil; 18 | import org.frameworkset.elasticsearch.serial.SerialUtil; 19 | import org.junit.Test; 20 | 21 | import java.util.HashMap; 22 | import java.util.Map; 23 | 24 | public class ScriptImpl7Test { 25 | @Test 26 | public void test(){ 27 | ScriptImpl7 script = new ScriptImpl7(); 28 | script.updateDocumentByScriptPath(); 29 | } 30 | 31 | @Test 32 | public void test1(){ 33 | ScriptImpl7 script = new ScriptImpl7(); 34 | script.updateDocumentByScriptQueryPath(); 35 | } 36 | 37 | public static void main(String[] args){ 38 | Map value = new HashMap(); 39 | value.put("aaa","\r\n\""); 40 | String _value = SerialUtil.object2json(value); 41 | value.put("aaa",_value); 42 | _value = SerialUtil.object2json(value); 43 | System.out.println(_value); 44 | value = SimpleStringUtil.json2Object(_value,HashMap.class); 45 | System.out.println(_value); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/script/ScriptImplTest.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.script;/* 2 | * Copyright 2008 biaoping.yin 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 | 17 | import com.frameworkset.util.SimpleStringUtil; 18 | import org.frameworkset.elasticsearch.serial.SerialUtil; 19 | import org.junit.Test; 20 | 21 | import java.util.HashMap; 22 | import java.util.Map; 23 | 24 | public class ScriptImplTest { 25 | @Test 26 | public void test(){ 27 | ScriptImpl script = new ScriptImpl(); 28 | script.updateDocumentByScriptPath(); 29 | } 30 | 31 | @Test 32 | public void test1(){ 33 | ScriptImpl script = new ScriptImpl(); 34 | script.updateDocumentByScriptQueryPath(); 35 | } 36 | 37 | public static void main(String[] args){ 38 | Map value = new HashMap(); 39 | value.put("aaa","\r\n\""); 40 | String _value = SerialUtil.object2json(value); 41 | value.put("aaa",_value); 42 | _value = SerialUtil.object2json(value); 43 | System.out.println(_value); 44 | value = SimpleStringUtil.json2Object(_value,HashMap.class); 45 | System.out.println(_value); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/serial/CharEscapeUtilTest.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.serial; 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 | 18 | import org.frameworkset.elasticsearch.serial.CharEscapeUtil; 19 | import org.junit.Test; 20 | 21 | /** 22 | *

Description:

23 | *

24 | *

Copyright (c) 2018

25 | * @Date 2019/8/20 10:17 26 | * @author biaoping.yin 27 | * @version 1.0 28 | */ 29 | public class CharEscapeUtilTest { 30 | @Test 31 | public void test(){ 32 | CharEscapeUtil charEscapeUtil = new CharEscapeUtil(); 33 | charEscapeUtil.writeString("asdfaf-|sss%7csdafasfd",false); 34 | String result = charEscapeUtil.toString(); 35 | System.out.println(result); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/sql/DocObject.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.sql; 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 | 18 | import com.frameworkset.orm.annotation.Column; 19 | 20 | import java.util.Date; 21 | 22 | /** 23 | *

Description:

24 | *

25 | *

Copyright (c) 2018

26 | * @Date 2018/9/17 10:49 27 | * @author biaoping.yin 28 | * @version 1.0 29 | */ 30 | public class DocObject { 31 | private int isnew; 32 | private Date createtime; 33 | private String content; 34 | private int documentId; 35 | private int channelId; 36 | 37 | /** 38 | * 通过column指定索引文档和对象属性的映射关系 39 | * 通过column注解还可以指定日期格式和时区信息 40 | * @Column(name="docInfo.author",dataformat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",timezone = "Etc/UTC",locale = "zh") 41 | * 42 | */ 43 | @Column(name="docInfo.author") 44 | private String docInfoAuthor; 45 | 46 | public int getIsnew() { 47 | return isnew; 48 | } 49 | 50 | public void setIsnew(int isnew) { 51 | this.isnew = isnew; 52 | } 53 | 54 | public Date getCreatetime() { 55 | return createtime; 56 | } 57 | 58 | public void setCreatetime(Date createtime) { 59 | this.createtime = createtime; 60 | } 61 | 62 | public String getContent() { 63 | return content; 64 | } 65 | 66 | public void setContent(String content) { 67 | this.content = content; 68 | } 69 | 70 | public int getDocumentId() { 71 | return documentId; 72 | } 73 | 74 | public void setDocumentId(int documentId) { 75 | this.documentId = documentId; 76 | } 77 | 78 | public int getChannelId() { 79 | return channelId; 80 | } 81 | 82 | public void setChannelId(int channelId) { 83 | this.channelId = channelId; 84 | } 85 | 86 | public String getDocInfoAuthor() { 87 | return docInfoAuthor; 88 | } 89 | 90 | public void setDocInfoAuthor(String docInfoAuthor) { 91 | this.docInfoAuthor = docInfoAuthor; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/sql/SQLTest.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.sql;/* 2 | * Copyright 2008 biaoping.yin 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 | 17 | import org.frameworkset.elasticsearch.ElasticSearchHelper; 18 | import org.frameworkset.elasticsearch.client.ClientInterface; 19 | import org.frameworkset.elasticsearch.handler.ESStringResponseHandler; 20 | import org.junit.Test; 21 | 22 | import java.util.HashMap; 23 | import java.util.Map; 24 | 25 | /** 26 | * 目前官方的jdbc驱动还没有放出来,先以rest sql api为例来介绍es 6.3.0的sql功能 27 | */ 28 | public class SQLTest { 29 | 30 | /** 31 | * 代码中的sql检索 32 | */ 33 | @Test 34 | public void testQuery(){ 35 | ClientInterface clientUtil = ElasticSearchHelper.getRestClientUtil(); 36 | String json = clientUtil.executeHttp("_sql?format=txt", 37 | "{\"query\": \"SELECT * FROM dbclobdemo\"}", 38 | ClientInterface.HTTP_POST,new ESStringResponseHandler("UTF-8") 39 | ); 40 | System.out.println(json); 41 | 42 | json = clientUtil.executeHttp("_sql?format=json", 43 | "{\"query\": \"SELECT * FROM dbclobdemo\"}", 44 | ClientInterface.HTTP_POST 45 | ); 46 | System.out.println(json); 47 | } 48 | 49 | /** 50 | * sql转换为dsl 51 | */ 52 | @Test 53 | public void testTranslate(){ 54 | ClientInterface clientUtil = ElasticSearchHelper.getRestClientUtil(); 55 | String json = clientUtil.executeHttp("_sql/translate", 56 | "{\"query\": \"SELECT * FROM dbclobdemo\"}", 57 | ClientInterface.HTTP_POST 58 | ); 59 | System.out.println(json); 60 | 61 | } 62 | 63 | /** 64 | * 配置文件中的sql dsl检索 65 | */ 66 | @Test 67 | public void testSQLQueryFromDSL(){ 68 | ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/sql.xml");//初始化一个加载sql配置文件的es客户端接口 69 | //设置sql查询的参数 70 | Map params = new HashMap(); 71 | params.put("channelId",1); 72 | String json = clientUtil.executeHttp("_sql","sqlQuery",params, 73 | ClientInterface.HTTP_POST 74 | ); 75 | System.out.println(json); 76 | 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/stop/StopTest.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.stop; 2 | /** 3 | * Copyright 2020 bboss 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 | 18 | import org.frameworkset.elasticsearch.ElasticSearchHelper; 19 | 20 | /** 21 | *

Description:

22 | *

23 | *

Copyright (c) 2020

24 | * @Date 2020/5/14 15:33 25 | * @author biaoping.yin 26 | * @version 1.0 27 | */ 28 | public class StopTest { 29 | public static void main(String[] args) { 30 | ElasticSearchHelper.getRestClientUtil(); 31 | ElasticSearchHelper.stopElasticsearch("default"); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/textembedding/TestTextEmbedding.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.textembedding; 2 | /** 3 | * Copyright 2025 bboss 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 | 18 | import org.junit.Test; 19 | 20 | /** 21 | * @author biaoping.yin 22 | * @Date 2025/5/11 23 | */ 24 | public class TestTextEmbedding { 25 | @Test 26 | public void testEmbedding(){ 27 | //Elasticsearch KNN search参考文档:https://www.elastic.co/docs/solutions/search/vector/knn#knn-search-filter-example 28 | TextEmbedding textEmbedding = new TextEmbedding(); 29 | textEmbedding.init(); 30 | textEmbedding.testCreateTextEmbeddingIndex(); 31 | textEmbedding.bulkdata(); 32 | textEmbedding.search(); 33 | textEmbedding.search1(); 34 | textEmbedding.searchWithFilter(); 35 | textEmbedding.searchWithScore(); 36 | } 37 | 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/thirddslcontainer/ScriptImpl7.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.thirddslcontainer;/* 2 | * Copyright 2008 biaoping.yin 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 | 17 | import org.bboss.elasticsearchtest.script.DynamicPriceTemplate; 18 | import org.bboss.elasticsearchtest.script.Rule; 19 | import org.frameworkset.elasticsearch.client.ClientInterface; 20 | 21 | import java.util.ArrayList; 22 | import java.util.HashMap; 23 | import java.util.List; 24 | import java.util.Map; 25 | 26 | public class ScriptImpl7 { 27 | private ClientInterface clientInterface; 28 | 29 | public ScriptImpl7(ClientInterface clientInterface) { 30 | this.clientInterface = clientInterface; 31 | } 32 | public void updateDocumentByScriptPath(){ 33 | //初始化数据,会创建type为demo的indice demo,并添加docid为2的文档 34 | DocumentCRUD7 documentCRUD = new DocumentCRUD7(clientInterface); 35 | documentCRUD.testCreateIndice(); 36 | documentCRUD.testBulkAddDocument(); 37 | //创建加载配置文件的客户端工具,用来检索文档,单实例多线程安全 38 | Map params = new HashMap(); 39 | DynamicPriceTemplate dynamicPriceTemplate = new DynamicPriceTemplate(); 40 | dynamicPriceTemplate.setGoodsId(1); 41 | List ruleList = new ArrayList(); 42 | Rule rule = new Rule(); 43 | rule.setRuleCount(100); 44 | rule.setRuleExist(true); 45 | rule.setRuleId("asdfasdfasdf"); 46 | ruleList.add(rule); 47 | 48 | rule = new Rule(); 49 | rule.setRuleCount(101); 50 | rule.setRuleExist(false); 51 | rule.setRuleId("bbb$b"); 52 | ruleList.add(rule); 53 | 54 | rule = new Rule(); 55 | rule.setRuleCount(103); 56 | rule.setRuleExist(true); 57 | rule.setRuleId("ccccc"); 58 | ruleList.add(rule); 59 | dynamicPriceTemplate.setRules(ruleList); 60 | 61 | //为id为2的文档增加last和nick两个属性 62 | params.put("last","gaudreau"); 63 | params.put("nick","hockey"); 64 | params.put("dynamicPriceTemplate",dynamicPriceTemplate); 65 | //通过script脚本为id为2的文档增加last和nick两个属性,为了演示效果强制refresh,实际环境慎用 66 | clientInterface.updateByPath("demo/_update/2?refresh","scriptDsl",params); 67 | //获取更新后的文档,会看到新加的2个字段属性 68 | String doc = clientInterface.getDocument("demo","2"); 69 | System.out.println(doc); 70 | 71 | } 72 | 73 | 74 | public void updateDocumentByScriptQueryPath(){ 75 | //初始化数据,会创建type为demo的indice demo,并添加docid为2的文档 76 | DocumentCRUD7 documentCRUD = new DocumentCRUD7(clientInterface); 77 | documentCRUD.testCreateIndice(); 78 | documentCRUD.testBulkAddDocument(); 79 | //创建加载配置文件的客户端工具,用来检索文档,单实例多线程安全 80 | Map params = new HashMap(); 81 | DynamicPriceTemplate dynamicPriceTemplate = new DynamicPriceTemplate(); 82 | dynamicPriceTemplate.setGoodsId(1); 83 | dynamicPriceTemplate.setGoodName("asd\"国家"); 84 | List ruleList = new ArrayList(); 85 | Rule rule = new Rule(); 86 | rule.setRuleCount(100); 87 | rule.setRuleExist(true); 88 | rule.setRuleId("asdfasd$fasdf"); 89 | ruleList.add(rule); 90 | 91 | rule = new Rule(); 92 | rule.setRuleCount(101); 93 | rule.setRuleExist(false); 94 | rule.setRuleId("bbbb"); 95 | ruleList.add(rule); 96 | 97 | rule = new Rule(); 98 | rule.setRuleCount(103); 99 | rule.setRuleExist(true); 100 | rule.setRuleId(null); 101 | ruleList.add(rule); 102 | dynamicPriceTemplate.setRules(ruleList); 103 | 104 | 105 | //为id为2的文档增加last和nick两个属性 106 | params.put("last","gaudre$au"); 107 | params.put("nick","hockey"); 108 | params.put("id",3); 109 | params.put("dynamicPriceTemplate",dynamicPriceTemplate); 110 | //通过script脚本为id为2的文档增加last和nick两个属性,为了演示效果强制refresh,实际环境慎用 111 | clientInterface.updateByPath("demo/_update_by_query?refresh","scriptDslByQuery",params); 112 | //获取更新后的文档,会看到新加的2个字段属性 113 | String doc = clientInterface.getDocument("demo","3"); 114 | System.out.println(doc); 115 | 116 | } 117 | 118 | 119 | } 120 | -------------------------------------------------------------------------------- /src/test/java/org/bboss/elasticsearchtest/xpack/CleanMonitor.java: -------------------------------------------------------------------------------- 1 | package org.bboss.elasticsearchtest.xpack; 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 | 18 | import org.frameworkset.elasticsearch.ElasticSearchHelper; 19 | import org.junit.Test; 20 | 21 | import java.io.UnsupportedEncodingException; 22 | 23 | /** 24 | *

Description:

25 | *

26 | *

Copyright (c) 2018

27 | * @Date 2018/10/24 18:48 28 | * @author biaoping.yin 29 | * @version 1.0 30 | */ 31 | public class CleanMonitor { 32 | @Test 33 | public void cleanXPaxkMonitor() throws UnsupportedEncodingException { 34 | ElasticSearchHelper.getRestClientUtil().cleanAllXPackIndices(); 35 | // ElasticSearchHelper.getRestClientUtil().removeAlias(".kibana",".kibana_1"); 36 | // ElasticSearchHelper.getRestClientUtil().dropIndice(".monitoring-es-7-2020.08.20"); 37 | // ElasticSearchHelper.getRestClientUtil().dropIndice("vops-chbizcollect-2020.08.18"); 38 | // ElasticSearchHelper.getRestClientUtil().dropIndice("vops-chbizcollect-2020.08.19"); 39 | // ElasticSearchHelper.getRestClientUtil().dropIndice("vops-chbizcollect-2020.08.20"); 40 | // ElasticSearchHelper.getRestClientUtil().removeAlias(".kibana_task_manager",".kibana_task_manager_1"); 41 | // ElasticSearchHelper.getRestClientUtil().dropIndice(".kibana"); 42 | // 43 | // ElasticSearchHelper.getRestClientUtil().dropIndice(".kibana_task_manager"); 44 | // System.out.println(ElasticSearchHelper.getRestClientUtil().getIndice(".kibana_task_manager")); 45 | // System.out.println(ElasticSearchHelper.getRestClientUtil().executeHttp(java.net.URLEncoder.encode(".kibana_*", "UTF-8") + "?pretty",HTTP_DELETE)); 46 | // ElasticSearchHelper.getRestClientUtil().deleteTempate("demotemplate_1"); 47 | // /.kibana_task_manager/_doc/_search 48 | 49 | // System.out.println(ElasticSearchHelper.getRestClientUtil().searchAll(".kibana_task_manager", MetaMap.class)); 50 | } 51 | } 52 | --------------------------------------------------------------------------------