当前位置: 首页 > news >正文

SpringBoot 集成 Elasticsearch

一、版本

spring-boot版本:2.3.7.RELEASEElasticsearch7.8.0

在这里插入图片描述

版本说明详见

二、Elasticsearch 下载和安装

Elasticsearch 下载
kibana下载
ik分词器下载

配置IK分词器

2.1 解压,在elasticsearch-7.8.0\plugins 路径下新建ik目录

在这里插入图片描述

2.2 将ik分词器解压放入ik目录

在这里插入图片描述

2.3 扩展词汇测试示例

2.3.1 ik/config 目录下新建custom.dic文件

在这里插入图片描述

2.3.2 编辑custom.dic文件,加入新词汇

注意:custom.dic文件内容的格式的编码为UTF-8格式编码,否则会导致扩展词汇失效。
在这里插入图片描述

2.3.3 打开 IKAnalyzer.cfg.xml 文件,将新建的 custom.dic 配置其中,如下图

在这里插入图片描述

2.4 编辑kibana.yml ,修改kibana配置

在这里插入图片描述

三、新建Springboot项目,整合Elasticsearch并测试

3.1 加入依赖,配置

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
spring: main: allow-bean-definition-overriding: true elasticsearch:rest:uris: http://localhost:9200

3.2 新建实体类SkuEs


@Data
@Document(indexName = "skues" ,shards = 3,replicas = 1)
public class SkuEs {// 商品Id= skuId@Idprivate Long id;@Field(type = FieldType.Text, analyzer = "ik_max_word")private String keyword;@Field(type = FieldType.Integer, index = false)private Integer skuType;@Field(type = FieldType.Integer, index = false)private Integer isNewPerson;@Field(type = FieldType.Long)private Long categoryId;@Field(type = FieldType.Text)private String categoryName;@Field(type = FieldType.Keyword, index = false)private String imgUrl;//  es 中能分词的字段,这个字段数据类型必须是 text!keyword 不分词!@Field(type = FieldType.Text)private String title;@Field(type = FieldType.Double)private Double price;@Field(type = FieldType.Integer, index = false)private Integer stock;@Field(type = FieldType.Integer, index = false)private Integer perLimit;@Field(type = FieldType.Integer, index = false)private Integer sale;@Field(type = FieldType.Long)private Long wareId;//  商品的热度!@Field(type = FieldType.Long)private Long hotScore = 0L;@Field(type = FieldType.Object, index = false)private List<String> ruleList;}

3.2 新建接口SkuRepository

public interface SkuRepository extends ElasticsearchRepository<SkuEs,Long> {}

3.3 测试

@Service
public class SkuServiceImpl implements SkuService {@Autowiredprivate SkuRepository skuRepository;@Overridepublic void upperSku(Long skuId) {//  3 调用方法添加ESSkuEs skuEs = new SkuEs();skuEs.setCategoryId(11111l);skuEs.setCategoryName("name");skuEs.setId(1123l);skuEs.setKeyword("keyword");skuEs.setWareId(1123l);skuEs.setIsNewPerson(12);skuEs.setImgUrl("url");skuEs.setTitle("SkuName");skuEs.setSkuType(0);skuEs.setPrice(123.1);skuEs.setStock(11);skuEs.setSale(21);skuEs.setPerLimit(123);skuRepository.save(skuEs);}
}

3.4 运行结果

打开kibana控制台:http://localhost:5601/app/kibana#/dev_tools/console
在这里插入图片描述

http://www.lryc.cn/news/103574.html

相关文章:

  • 【ES】使用日志记录
  • svn还原本地代码
  • zore-shot,迁移学习和多模态学习
  • 【Golang 接口自动化07】struct转map的三种方式
  • 华为数通HCIA-网络模型
  • 端口的解说
  • “深入了解Spring Boot: 快速构建微服务应用的利器“
  • 华为OD机试 Java 实现【批量处理任务】【2023 B卷 200分】,二分查找
  • C# 2的幂
  • linux vi指令大全
  • jdk8使用okhttp发送http2请求
  • virbr是什么设备
  • MyBatis缓存-提高检索效率的利器--二级缓存
  • 开心档之CSS !important 规则
  • 深入篇【C++】手搓模拟实现list类(详细剖析底层实现原理)模拟实现正反向迭代器【容器适配器模式】
  • OnTrigger的几种情况
  • 地产变革中,物业等风来
  • (五)springboot实战——springboot自定义事件的发布和订阅
  • AVFoudation - 音频测量
  • 学习记录——TransNormerLLM
  • 【Qt】利用Tool Button控件创建下拉菜单按钮
  • 1.2 eureka注册中心,完成服务注册
  • 【100天精通python】Day20:文件及目录操作_os模块和os.psth模块,文件权限修改
  • 回归预测 | MATLAB实现PSO-GPR粒子群优化高斯过程回归多输入单输出回归预测
  • python_PyQt5开发验证K线视觉想法工具V1.1 _增加标记类型_线段
  • 中文多模态医学大模型智能分析X光片,实现影像诊断,完成医生问诊多轮对话
  • 企业服务器数据库被360后缀勒索病毒攻击后采取的措施
  • FFmpeg-两个文件mix重采样以那个为主
  • 【WebGL】初探WebGL,我了解到这些
  • fwft fifo和standard fifo