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

ES知识点二

数据聚合

DSL聚合

JavaRestClient聚合

示例:

SpringBoot整合ES

第一步:引入依赖

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-elasticsearch</artifactId> </dependency>

第二步:配置文件

# es的配置 spring: elasticsearch: uris: http://192.168.21.128:9200 data: elasticsearch: repositories: enabled: true

第三步:创建实体类

@Data @Document(indexName = "article") public class Article { @Id @Field(index=false,type = FieldType.Integer) private Integer id; @Field(analyzer = "ik_smart",searchAnalyzer = "ik_smart",store = true,type = FieldType.Text) private String title; @Field(analyzer = "ik_smart",searchAnalyzer = "ik_smart",store = true,type = FieldType.Text) private String context; @Field(store = true,type = FieldType.Integer) private Integer hits; }

代码示例:

@Test void testSave() { for (int i = 1; i < 11; i++) { Article article = new Article(); article.setId(i); article.setTitle("sd-测试标题" + i); article.setContext("sd-测试内容" + i); article.setHits(100+i); articleMapper.save(article); } } @Test void testDelete() { articleMapper.deleteById(1); } @Test void testUpdate() { Article article = new Article(); article.setId(1); article.setTitle("测试标题1"); article.setContext("测试内容1"); articleMapper.save(article); } //查询所有 @Test void testFindAll() { Iterable<Article> articles = articleMapper.findAll(); for (Article article : articles) { System.out.println(article); } } //主键查询 @Test void testFindById() { Optional<Article> byId = articleMapper.findById(1); System.out.println(byId.get()); } //分页查询 @Test void testFindAllWithPage() { Pageable pageable = PageRequest.of(0, 3); Page<Article> articles = articleMapper.findAll(pageable); articles.forEach(System.out::println); } //排序查询 @Test void testFindAllWithSort() { Sort sort = Sort.by(Sort.Order.desc("hits")); Iterable<Article> all = articleMapper.findAll(sort); all.forEach(System.out::println); } //分页+排序查询 @Test void testFindAllWithPageAndSort() { Sort sort = Sort.by(Sort.Order.desc("hits")); Pageable pageable = PageRequest.of(0, 3,sort); Page<Article> articles = articleMapper.findAll(pageable); articles.forEach(System.out::println); } //根据标题查询 @Test void testFindByTitle() { Pageable pageable = PageRequest.of(0, 10); Page<Article> articles = articleMapper.findByTitle("sd-测试标题", pageable); articles.forEach(System.out::println); } //根据标题或内容查询 @Test void testFindByContext() { Pageable pageable = PageRequest.of(0, 10); Page<Article> articles = articleMapper.findByTitleOrContext("标题", "内容", pageable); articles.forEach(System.out::println); } //根据点击量范围查询 @Test void testFindByHitsBetween() { Pageable pageable = PageRequest.of(0, 10); Page<Article> articles = articleMapper.findByHitsBetween(100, 106, pageable); articles.forEach(System.out::println); } //查询少于指定点击量的文章 @Test void testFindByHitsLessThan() { Pageable pageable = PageRequest.of(0, 10); Page<Article> articles = articleMapper.findByHitsLessThan(103, pageable); articles.forEach(System.out::println); } //查询大于指定点击量的文章 @Test void testFindByHitsGreaterThan() { Pageable pageable = PageRequest.of(0, 10); Page<Article> articles = articleMapper.findByHitsGreaterThan(107, pageable); articles.forEach(System.out::println); }

命名规则查询

ES集群搭建

ES集群的节点角色

ES集群的脑裂:

故障转移:

http://www.jsqmd.com/news/120328/

相关文章:

  • 2025年度最值得入手的国产儿童鞋服品牌大盘点 - 品牌测评鉴赏家
  • C#之Modbus-RTU通讯-读取输出寄存器-整数
  • 【课程设计/毕业设计】基于springboot的社区团购系统的设计与实现商品管理、团长运营、订单处理、售后跟踪等功能【附源码、数据库、万字文档】
  • 休闲无聊测试AI大模型生成
  • 视频播放器PotPlayer下载安装教程:超详细图文步骤(PC+安卓)
  • 【路径规划】基于RRT算法结合卡尔曼滤波器相实现定位不确定环境下移动机器人路径规划附matlab代码
  • 【油井】基于matlab模拟隐式二维油井(含渗透率和压力随时间的变化)
  • python多表关联防注入sql
  • 2025年中国十大童装品牌盘点:从品质到风格,哪款戳中你的心? - 品牌测评鉴赏家
  • 【课程设计/毕业设计】基于springBoot物业智慧系统设计与实现基于springboot的物业报修系统的设计与实现【附源码、数据库、万字文档】
  • Java计算机毕设之基于springboot的幼儿园管理系统的设计与实现为幼儿园(含普惠园、民办园、连锁园)设计的 “家园共育 + 日常运营 + 安全监管(完整前后端代码+说明文档+LW,调试定制等)
  • Java毕设选题推荐:基于springboot的幼儿园管理系统的设计与实现幼儿信息管理(基本资料、健康档案、接送记录)【附源码、mysql、文档、调试+代码讲解+全bao等】
  • 完整教程:npu_moe_distribute_combine算子代码分析
  • 用 .NET MAUI 10 + VS Copilot 从 0 开发一个签到 App(六)登录
  • 信息学奥赛一本通 1616:A 的 B 次方
  • 微信开发者secret和appid获取方法
  • 解锁大模型“能干活“的秘诀:RAG×MoE技术组合深度解析
  • Java毕设选题推荐:基于Java+springboot招投标管理系统设计与实现基于springboot的在线招标系统的设计与实现【附源码、mysql、文档、调试+代码讲解+全bao等】
  • 2025 --【J+S 二十连测】-- 第十二套 总结+题解
  • Java计算机毕设之基于springboot的在线招标系统的设计与实现基于springboot招投标管理系统设计与实现(完整前后端代码+说明文档+LW,调试定制等)
  • 深入解析MySQL事务与锁:构建高并发数据系统的基石
  • android kotlinx.serialization用法和封装全解
  • 系统架构设计师教程资源合集
  • 什么是八股文?Java程序员春招如何提前储备?拿高薪offer?
  • 创新点解读:基于贝叶斯优化PatchTST的时间序列预测算法(附代码实现)
  • 【毕业设计】基于springboot的幼儿园管理系统的设计与实现(源码+文档+远程调试,全bao定制等)
  • AI伦理风险防控与治理体系构建 守护技术向善之路
  • AI应用架构师如何实现高效的上下文理解增强方案?
  • 吐血整理!儿童鞋服宝藏品牌大盘点 - 品牌测评鉴赏家
  • 创新点解读:基于非线性二次分解的Ridge-RF-XGBoost时间序列预测(附代码实现)