news 2026/4/18 7:49:40

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/4/16 16:04:57

AI伦理风险防控与治理体系构建 守护技术向善之路

人工智能的飞速发展在推动社会进步的同时&#xff0c;也催生了一系列伦理风险&#xff0c;数据泄露、算法偏见、责任认定难题等问题逐渐凸显&#xff0c;对社会公平和个体权益构成挑战。如何防范伦理风险&#xff0c;构建科学有效的治理体系&#xff0c;引导AI技术“向善”发展…

作者头像 李华
网站建设 2026/4/18 3:51:37

什么是八股文?Java程序员春招如何提前储备?拿高薪offer?

八股文与Java程序员春招备战指南什么是八股文&#xff1f;八股文原指中国古代科举考试中一种固定格式的应试文体&#xff0c;在现代互联网行业面试场景中&#xff0c;特指技术面试中常见的标准化问题和考察点。对于Java程序员而言&#xff0c;八股文通常包括&#xff1a;Java基…

作者头像 李华
网站建设 2026/4/18 3:52:39

跨境电子商务综合试验区DID(内含七批试验区名单)

数据简介 跨境电子商务综合试验区作为一类独具特色的经济功能区域&#xff0c;其核心使命在于加速国际跨境电子商务领域的拓展步伐与创新进程。这类试验区一般由国家或地方政府主导设立&#xff0c;致力于推动电子商务贸易、数字经济及国际贸易的整体跃升。 跨境电子商务综合…

作者头像 李华
网站建设 2026/4/18 2:44:36

Java计算机毕设之基于springboot的泳衣泳帽游泳用品专卖店系统的设计与实现基于springboot的游泳用品专卖店系统的设计与实现(完整前后端代码+说明文档+LW,调试定制等)

博主介绍&#xff1a;✌️码农一枚 &#xff0c;专注于大学生项目实战开发、讲解和毕业&#x1f6a2;文撰写修改等。全栈领域优质创作者&#xff0c;博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java、小程序技术领域和毕业项目实战 ✌️技术范围&#xff1a;&am…

作者头像 李华
网站建设 2026/4/18 3:51:34

BNO055九轴传感器原理图设计,已量产(加速度传感器)

目录 1、电源:传感器对噪声 “零容忍”,近件去耦是关键 2、配置引脚:别漏了上拉,不然芯片 “启动失常” 3、时钟:32.768KHz 晶振,负载电容必须 “对号入座” 4、复位:RC 上电复位,时间常数要 “够稳” 5、通信与中断:I2C 地址可配置,中断省掉轮询 6、SOC 传感器…

作者头像 李华
网站建设 2026/4/17 8:44:49

大学生必备6个AI论文工具:轻松搞定论文效率飙升告别熬夜!

如果你是正在为毕业论文熬夜、被导师催稿、对着查重报告唉声叹气的大学生或研究生&#xff0c;请停下来&#xff01;你不是一个人在战斗。我们深知你的痛苦&#xff1a;选题毫无头绪、文献综述无从下笔、问卷数据一团糟、导师的修改意见像天书&#xff0c;更别提那令人心梗的查…

作者头像 李华