一、介绍
二、安装
npm run start
-Xms512M-Xmx512M
三、ElasticSearch简单测试
四、整合elasticsearch
/*** 用户实体类*/@Document(indexName = "user",type = "info")public class User {private Integer id;private String name;private Integer age;public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public Integer getAge() {return age;}public void setAge(Integer age) {this.age = age;}}
ElasticsearchRepository
/*** user的持久层&#xff0c;继承了ElasticsearchRepository*/&#64;Repositorypublic interface UserRepository extends ElasticsearchRepository<User,Integer> {}
&#64;RestController&#64;RequestMapping("/user/info")public class UserController {&#64;Autowiredprivate UserRepository repository;//1.保存数据到索引&#64;GetMapping("/save")public Object save(){User user &#61; new User();user.setId(2);user.setName("张三");user.setAge(21);repository.save(user);return JsonData.buildSuccess();}//2.从索引检索数据&#64;GetMapping("/search")public Object search(String name){QueryBuilder builder &#61; QueryBuilders.matchQuery("name",name);Iterable<User> list &#61; repository.search(builder);return JsonData.buildSuccess(list);}}