当前位置: 首页 > 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.gsyq.cn/news/132429.html

相关文章:

  • 【课程设计/毕业设计】基于springboot的社区团购系统的设计与实现商品管理、团长运营、订单处理、售后跟踪等功能【附源码、数据库、万字文档】
  • 休闲无聊测试AI大模型生成
  • 【油井】基于matlab模拟隐式二维油井(含渗透率和压力随时间的变化)
  • Java计算机毕设之基于springboot的幼儿园管理系统的设计与实现为幼儿园(含普惠园、民办园、连锁园)设计的 “家园共育 + 日常运营 + 安全监管(完整前后端代码+说明文档+LW,调试定制等)
  • 2025年中国十大童装品牌盘点:从品质到风格,哪款戳中你的心? - 品牌测评鉴赏家
  • Java计算机毕设之基于springboot的在线招标系统的设计与实现基于springboot招投标管理系统设计与实现(完整前后端代码+说明文档+LW,调试定制等)
  • Java毕设选题推荐:基于Java+springboot招投标管理系统设计与实现基于springboot的在线招标系统的设计与实现【附源码、mysql、文档、调试+代码讲解+全bao等】
  • 微信开发者secret和appid获取方法
  • AI伦理风险防控与治理体系构建 守护技术向善之路
  • 吐血整理!儿童鞋服宝藏品牌大盘点 - 品牌测评鉴赏家
  • I/O多路复用
  • Vue.js:轻量高效的渐进式前端框架,为何成为开发者首选?
  • 生成式AI重构内容生态 人机协同定义创作新范式
  • Vue.js从入门到实战:一站式学习指南
  • 68
  • Semantic Kernel使用连接器进行向量搜索
  • 2025儿童鞋服品牌Top10揭晓!这些品牌凭什么征服家长? - 品牌测评鉴赏家
  • ESA正式授予Sivers波束成形技术开发合同
  • 第196期 TRAE 与 Amazon Kiro 智能体驱动集成开发环境(Agentic IDE)对比 - 详解
  • 第2章:LangChain大模型工具开发(Agent工具能力)
  • 跨境电子商务综合试验区DID(内含七批试验区名单)
  • 宝妈必看!2025高性价比儿童鞋服品牌红榜,安全舒适还省钱 - 品牌测评鉴赏家
  • 面向对象和异常
  • 再见,Kimi?月活不及豆包 5%,谁是下一个王?
  • Java计算机毕设之基于springboot的泳衣泳帽游泳用品专卖店系统的设计与实现基于springboot的游泳用品专卖店系统的设计与实现(完整前后端代码+说明文档+LW,调试定制等)
  • 单向循环链表
  • 2025年12月中国童装品牌深度调研:男生女生童装舒适度与性价比分析报告 - 品牌测评鉴赏家
  • Semantic Kernel 实战系列(七) - 高级主题 - Agents 与多代理系统
  • 《手搓》线程池优化的追求
  • mengzhu铃声