依赖配置
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
索引操作
建立索引
@Autowired
ElasticsearchOperations elasticsearchOperations;
@Test
void insert(){
IndexOperations indexOperations = elasticsearchOperations.indexOps(Book.class);
}
删除索引
@Autowired
ElasticsearchOperations elasticsearchOperations;
@Test
void save(){
String delete = elasticsearchOperations.delete(Book.class);
}
操作
添加
@Autowired
ElasticsearchRestTemplate elasticsearchRestTemplate;
Book build = Book.builder()
.bid(UUID.randomUUID().toString())
.time(LocalDate.now())
.build();
Book save = elasticsearchRestTemplate.save(build);