dawdler-client-plug-es
模块介绍
实现web端注入EsOperator的功能.
1. pom中引入依赖
<groupId>club.dawdler</groupId>
<artifactId>dawdler-client-plug-es</artifactId>
2. 使用方式
通过@EsInjector注解标识全局变量为EsOperator类型的变量即可.
@Controller
public class UserController{
@EsInjector("myEs")//myEs为配置文件的名称,不包含后缀properties
EsOperator esOperator;
@RequestMapping(value = "/getUser", method = RequestMethod.GET)
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;
}
}