From ff70c1f5c1a4857c235422e0f3f615765d78a76c Mon Sep 17 00:00:00 2001 From: wanghaun Date: Tue, 21 Jun 2022 23:59:45 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feature/module=5Fsplit=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=AF=B4=E6=98=8E=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c3a2eed..c240d9c 100644 --- a/README.md +++ b/README.md @@ -563,4 +563,6 @@ elasticsearch 版本支持 v6 和 v7 ## 参考及引用 -本项目 注解查询参考了 开源项目 https://gitee.com/JohenTeng/elasticsearch-helper \ No newline at end of file +本项目 注解查询参考了 开源项目 https://gitee.com/JohenTeng/elasticsearch-helper + +ff \ No newline at end of file -- Gitee From 8b7b2a8c726478074f9b09825b8519bac95e540b Mon Sep 17 00:00:00 2001 From: wanghaun Date: Wed, 22 Jun 2022 00:00:08 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feature/module=5Fsplit=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=AF=B4=E6=98=8E=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index c240d9c..c3a2eed 100644 --- a/README.md +++ b/README.md @@ -563,6 +563,4 @@ elasticsearch 版本支持 v6 和 v7 ## 参考及引用 -本项目 注解查询参考了 开源项目 https://gitee.com/JohenTeng/elasticsearch-helper - -ff \ No newline at end of file +本项目 注解查询参考了 开源项目 https://gitee.com/JohenTeng/elasticsearch-helper \ No newline at end of file -- Gitee From 43fbb808be88c0cbaaef1637c230c91ca93523e8 Mon Sep 17 00:00:00 2001 From: wanghaun Date: Wed, 22 Jun 2022 00:24:51 +0800 Subject: [PATCH 3/3] =?UTF-8?q?feature/module=5Fsplit=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=AF=B4=E6=98=8E=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.en.md | 188 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 164 insertions(+), 24 deletions(-) diff --git a/README.en.md b/README.en.md index 5906852..391d758 100644 --- a/README.en.md +++ b/README.en.md @@ -1,36 +1,176 @@ # elasticsearch-engine -#### Description -elasticsearch 查询引擎, 基于注解,sql,原生语句查询. 并整合 mybatis , spring data jpa +## introduce -#### Software Architecture -Software architecture description +elasticsearch-engine is an ElasticSearch query engine framework encapsulated based on HighLevelRestClient. Supports ElasticSearch annotation-based structured query; +Query based on sql statement; +And integrate common ORM framework, provide Mapper interface based on ORM framework to automatically generate ElasticSearch Sql query statement, and execute ElasticSearch query; -#### Installation +**You can implement ElasticSearch query by marking an annotation on the Mapper interface that needs to query ElasticSearch without additional code development; +And you can dynamically switch the query between ElasticSearch and Mysql through the configuration center configuration, +Implement ElasticSearch query downgrade.** -1. xxxx -2. xxxx -3. xxxx +## Main features -#### Instructions +1. Implement elasticsearch query based on annotations -1. xxxx -2. xxxx -3. xxxx +2. Implement elasticsearch query based on sql statement -#### Contribution +3. Automatically generate elasticsearch queries based on the mybatis mapper interface, and support database return table queries -1. Fork the repository -2. Create Feat_xxx branch -3. Commit your code -4. Create Pull Request +4. Automatically generate elasticsearch query based on jpa repository interface, and support database return table query +5. Automatically generate elasticsearch query based on jooq dao implementation class, and support database return table query -#### Gitee Feature +## Architecture modules -1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md -2. Gitee blog [blog.gitee.com](https://blog.gitee.com) -3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) -4. The most valuable open source project [GVP](https://gitee.com/gvp) -5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) -6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) +1. elasticsearch-engine-base provides basic functions such as annotation query, sql statement query, ORM query sql parsing, sql rewriting and so on +2. elasticsearch-engine-mybatis implements sql interception, rewriting, and execution of elasticsearch queries based on mybatis interceptor +3. elasticsearch-engine-jpa is based on aop, hibernate sql interceptor and re-jpa parameter binding module to realize sql interception, rewrite and execute elasticsearch query +4. elasticsearch-engine-jooq is based on aop, jooq execution listener to implement sql interception, rewrite, and execute elasticsearch queries + +## Instructions for use +For all complete examples, please refer to [Example](https://gitee.com/my-source-project/elasticsearch-engine-demo) + +### 1. Annotation query + +#### 1.1 Complex parameters + +1) Add maven dependencies + +````xml + + + com.elasticsearch.engine + elasticsearch-engine-base + 0.0.1-SNAPSHOT + +```` + +2) Define the query model + +````java +package com.elasticsearch.engine.demo.dto.query; + +import com.elasticsearch.engine.base.mapping.annotation.*; +import com.elasticsearch.engine.base.mapping.model.extend.PageParam; +import com.elasticsearch.engine.base.mapping.model.extend.RangeParam; +import com.elasticsearch.engine.base.mapping.model.extend.SignParam; +import com.elasticsearch.engine.base.model.annotion.Base; +import com.elasticsearch.engine.base.model.annotion.EsQueryIndex; +import com.elasticsearch.engine.base.model.annotion.Ignore; +import com.elasticsearch.engine.base.model.emenu.EsConnector; +import lombok.Data; + +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.util.List; + +/** + * @author wanghuan + * @description: Basic test for parsing query annotations + * @mail 958721894@qq.com + * @date 2022-05-31 22:40 + */ +@EsQueryIndex(value = "person_es_index") +@Data +public class PersonBaseQuery { + + @Term + private BigDecimal salary; + + @Terms(value = @Base("item_no")) + private List personNos; + + @Terms + private List personNoList; + + @Range(value = @Base(value = "status", connect = EsConnector.SHOULD), tag = Range.LE_GE) + private RangeParam rangeStatus; + + @Range + private RangeParam createTime; + + @WildCard + private String address; + + @Prefix + private String personName; + + @To(@Base("create_time")) + private LocalDateTime createTimeEnd; + + @From(value = @Base("create_time")) + private LocalDateTime createTimeStart; + + @PageAndOrder + private PageParam pageParam; + + /** + * Mark annotations do not parse the value, only parse the annotation value + * It is necessary to set the value value to be not empty, the query condition will take effect, but the set value will not be parsed, just mark whether to add the condition + * So value can be set arbitrarily, but note that string cannot be an empty string, and the array type cannot be null + * + * SignParam represents an unparsed parameter value type + * can also be represented using Sign.DEFAULT_STRING + */ + @Sort + private SignParam sortStatus; + + @Aggs(value = @Base("status"), type = Aggs.COUNT_DESC) + private SignParam groupStatus; + + /** + * Indicates that a field is ignored, and the ignored field will not be parsed when querying whether the attribute value is empty or not + */ + @Ignore + private String token; + +} +```` + +3) Declare the query interface + +````java + +@EsQueryIndex("person_es_index") +public interface PersonEsModelRepository extends BaseESRepository { + /** + * queryByMode + * + * @param param + * @return + */ + List queryByMode(PersonBaseQuery param); +} + +```` + +4) Test example + +````java + +@Slf4j +@RunWith(SpringRunner.class) +@SpringBootTest +public class EsEngineProxyModelQueryTest { + @Resource + private PersonEsModelRepository personEsModelRepository; + + /** + * model query test + */ + @Test + public void queryByModelTest() { + PersonBaseQuery person = new PersonBaseQuery(); + person.setPageParam(PageParam.builderPage().currentPage(1).pageSize(100).build()); + person.setSalary(new BigDecimal("67700")); + person.setPersonName("Zhang"); + person.setAddress("Tianfu"); + person.setCreateTimeStart(LocalDateTime.now().minusDays(300)); + person.setCreateTimeEnd(LocalDateTime.now()); + List res = personEsModelRepository.queryByMode(person); + log.info("res:{}", JsonParser.asJson(res)); + } +} +```` \ No newline at end of file -- Gitee