dawdler-server-plug-es
模块介绍
实现dawdler-server端注入EsOperator的功能.
1. pom中引入依赖
<groupId>club.dawdler</groupId>
<artifactId>dawdler-server-plug-es</artifactId>
2. 使用方式
通过@EsInjector注解标识全局变量为EsOperator类型的变量即可.
public class UserServiceImpl implements UserService {
@EsInjector("myEs")//myEs为配置文件的名称,不包含后缀properties
EsOperator esOperator;
public User getUser(String userId) {
SearchRequest searchRequest = new SearchRequest();
searchRequest.indices("product");
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
MatchQueryBuilder matchQueryBuilder = new MatchQueryBuilder("name", "电冰箱");
searchSourceBuilder.query(matchQueryBuilder);
searchRequest.source(searchSourceBuilder);
SearchResponse response = esOperator.search(searchRequest, Product.class);//使用esOperator对象
System.out.println(response);
return null;
}
}