文章合集
pom 引入依赖
<!-- springboot 整合ES -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
yml配置
spring:
data:
elasticsearch:
####集群名称
cluster-name: elasticsearch
####地址
cluster-nodes: 192.168.112.143:9300
新建索引实体类
/*goods 为 es 索引*/
@Document(indexName = "goods", type = "goods")
@Data
public class ProductEntity {
/** 主键ID */
private Integer id;
/** 类型ID */
private Integer categoryId;
/** 名称 */
private String name;
/** 小标题 */
private String subtitle;
/** 主图像 */
private String mainImage;
/** 小标题图像 */
private String subImages;
/** 描述 */
private String detail;
}
新建工具类
/**
* @author 索悻流年
* @title:
*/
public interface ProductReposiory extends ElasticsearchRepository<ProductEntity, Long> {
}
使用
public class ProductListener {
@Autowired
private ProductReposiory productReposiory;
public void sendData(){
ProductEntity productEntity = new ProductEntity();
productEntity.setName("测试");
/*保存数据*/
productReposiory.save(productEntity);
/*删除数据*/
productReposiory.delete(productEntity);
}
}
main 方法
@SpringBootApplication
public class AppGoodsCanal {
public static void main(String[] args) {
SpringApplication.run(AppGoodsCanal.class,args);
}
}
网友评论