This action will force synchronization from ymm-tech/ebatis, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
ebatis
是一个声明式Elasticsearch ORM
框架。只需要定义接口,便可轻松访问Elasticsearch
。ebatis
优雅地帮你隔离业务对Elasticserach
底层驱动接口的直接调用,你不再需要自己手动去构建繁琐DSL
语句。同时,当升级Elastisearch
版本的时候,业务可以完全不用关心底层接口的变动,平滑升级。
目前,支持Elastisearch
6.5.1
与7.5.1
版本。
ebatis
已经在满帮业务系统上稳定运行近一年,承载着每日近十亿次搜索服务。
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
表示ebatis
在Elasticsearch 7.5.1
版本上迭代的第三次版本。
使用手册:https://github.com/ymm-tech/ebatis/wiki
相关文章:https://www.infoq.cn/article/u4Xhw5Q3jfLE1brGhtbR
相关文章:https://mp.weixin.qq.com/s/GFRiiQEk-JLpPnCi_WrRqw
钉钉
开源项目需要的是持续地坚持,而我们坚持的动力当然也来自于你们的支持,希望你 来都来了,加个关注再走吧
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。