news 2026/8/7 6:37:43

ES知识点二

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
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集群的脑裂:

故障转移:

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/8/6 19:50:43

I/O多路复用

一.什么是I/O多路复用核心思想&#xff1a;通过一个线程同时管理多个 Socket&#xff08;文件描述符&#xff09;&#xff0c;在一个线程内同时检测 多个连接的状态&#xff08;如是否可读/可写&#xff09;&#xff0c;从而实现高效的并发处理。在 Linux 中&#xff0c;常见的…

作者头像 李华
网站建设 2026/8/7 3:10:19

视频播放器PotPlayer下载安装教程:超详细图文步骤(PC+安卓)

想找一个功能强大的视频播放器&#xff0c;却发现很多播放器要么广满屏&#xff0c;要么格式支持不全&#xff1f; 其实&#xff0c;PotPlayer 是一个非常好用播放器&#xff0c;支持几乎主流视频音频格式&#xff0c;而且解码能力极强。问题是——网上的 PotPlayer 下载安装教…

作者头像 李华
网站建设 2026/8/7 11:20:09

Semantic Kernel 实战系列(六) - Memory与向量存储

目录 1 Memories 的核心机制 2 向量存储集成 3 RAG&#xff08;Retrieval-Augmented Generation&#xff09;模式 4 内存管理和优化 5 实际应用&#xff1a;一个知识库聊天机器人 在上几篇文章中&#xff0c;我们探讨了Semantic Kernel的规划器如何自动化多步任务&#xf…

作者头像 李华
网站建设 2026/8/7 3:10:23

Semantic Kernel 实战系列(七) - 高级主题 - Agents 与多代理系统

目录 1 Agents 的概念 2 实时集成与多模态 3 安全与观测性 4 部署与扩展 5 未来趋势 在上几篇文章中&#xff0c;我们已经深入探讨了Semantic Kernel的Memory机制和向量存储&#xff0c;这些工具让AI应用像传统数据库系统一样可靠&#xff0c;能处理海量知识。 我总是认为…

作者头像 李华
网站建设 2026/8/6 5:30:27

LeetCode每日一题——K个一组翻转链表

题目描述&#xff1a;给定链表的头节点head&#xff0c;每 k 个节点一组进行翻转&#xff0c;返回操作后的链表。示例&#xff1a;输入&#xff1a;head [1,2,3,4,5], k 2 输出&#xff1a;[2,1,4,3,5]我们可以先处理翻转整个链表的情况ListNode* reverseList(ListNode* head…

作者头像 李华