1 Star 0 Fork 64

michael / ebatis

forked from ymm-tech / ebatis 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

ebatis是什么

GitHub Stars JDK support Maven Central License
ebatis是一个声明式Elasticsearch ORM框架。只需要定义接口,便可轻松访问Elasticsearchebatis优雅地帮你隔离业务对Elasticserach底层驱动接口的直接调用,你不再需要自己手动去构建繁琐DSL 语句。同时,当升级Elastisearch版本的时候,业务可以完全不用关心底层接口的变动,平滑升级。
目前,支持Elastisearch 6.5.17.5.1版本。

ebatis现状

ebatis已经在满帮业务系统上稳定运行近一年,承载着每日近十亿次搜索服务。

QUICK START

POM依赖(目前也支持6.5.1.2.RELEASE

<dependency>
     <groupId>io.manbang</groupId>
     <artifactId>ebatis-core</artifactId>
     <version>7.5.1.4.RELEASE</version>
</dependency>

创建集群连接如下:

@AutoService(ClusterRouterProvider.class)
public class SampleClusterRouterProvider implements ClusterRouterProvider {
    public static final String SAMPLE_CLUSTER_NAME = "sampleCluster";
 
    @Override
    public ClusterRouter getClusterRouter(String name) {
        if (SAMPLE_CLUSTER_NAME.equalsIgnoreCase(name)) {
            Cluster cluster = Cluster.simple("127.0.0.1", 9200, Credentials.basic("admin", "123456"));
            return ClusterRouter.single(cluster);
        } else {
            return null;
        }
    }
}

定义POJO对象如下:

@Data
public class RecentOrder {
    private Long cargoId;
    private String driverUserName;
    private String loadAddress;
    private Boolean searchable;
    private Integer companyId;
}

@Data
public class RecentOrderCondition {
    private Boolean searchable;

    private String driverUserName;
}

定义Mapper接口

@Mapper(indices = "recent_order_index")
public interface RecentOrderRepository {
    @Search
    List<RecentOrder> search(RecentOrderCondition condition);
}

测试接口如下:

@Slf4j
public class OrderRepositoryTest {
 
    @Test
    public void search() {
        // 组装查询条件
        RecentOrderCondition condition = new RecentOrderCondition();
        condition.setSearchable(Boolean.TRUE);
        condition.setDriverUserName("张三");
 
        // 映射接口
        RecentOrderRepository repository = MapperProxyFactory.getMapperProxy(RecentOrderRepository.class, SampleClusterRouterProvider.SAMPLE_CLUSTER_NAME);
 
        // 搜索货源
        List<RecentOrder> orders = repository.search(condition);
 
        // 断言
        Assert.assertEquals(3, orders.size());
 
        // 打印输出
        orders.forEach(order -> log.info("{}", order));
    }
}

搜索得DSL语句如下:

{
  "query" : {
    "bool" : {
      "must" : [ {
        "term" : {
          "searchable" : {
            "value" : true,
            "boost" : 1.0
          }
        }
      }, {
        "term" : {
          "driverUserName" : {
            "value" : "张三",
            "boost" : 1.0
          }
        }
      } ],
      "adjust_pure_negative" : true,
      "boost" : 1.0
    }
  },
  "_source" : {
    "includes" : [ "cargoId", "driverUserName", "loadAddress", "searchable", "companyId" ],
    "excludes" : [ ]
  }
}

ebatis版本使用xx.xx.xx.xx.RELEASE表示,前三位代表Elasticsearch适配集群的驱动版本,后一位代表ebatis在此版本上的迭代。例如7.5.1.3.RELEASE表示ebatisElasticsearch 7.5.1版本上迭代的第三次版本。

ebatis入门及相关文章

使用手册:https://github.com/ymm-tech/ebatis/wiki
相关文章:https://www.infoq.cn/article/u4Xhw5Q3jfLE1brGhtbR
相关文章:https://mp.weixin.qq.com/s/GFRiiQEk-JLpPnCi_WrRqw

交流群

钉钉

支持我们

你可以打赏我们 :coffee: 来杯咖啡 :coffee:

也可以点个 Star

开源项目需要的是持续地坚持,而我们坚持的动力当然也来自于你们的支持,希望你 :point_right: 来都来了,加个关注再走吧 :point_left:

MIT License Copyright (c) 2020 AMH Group Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

ebatis 是一个简单方便上手的 Elasticsearch ORM 框架。 展开 收起
Java
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/michael108/ebatis.git
git@gitee.com:michael108/ebatis.git
michael108
ebatis
ebatis
master

搜索帮助