news 2026/3/24 10:26:35

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/3/19 23:39:45

Python CGI 编程

Python CGI 编程 引言 CGI(Common Gateway Interface,通用网关接口)是一种网络服务器与执行程序之间进行通信的协议。Python作为一种功能强大、易学易用的编程语言,在CGI编程中得到了广泛应用。本文将详细介绍Python CGI编程的相关知识,包括Python CGI的基础概念、环境搭…

作者头像 李华
网站建设 2026/3/24 16:17:17

宏任务与微任务:前端面试必考执行顺序

宏任务 / 微任务执行顺序&#xff08;经典面试题详解&#xff09;你关注的宏任务、微任务执行顺序是前端面试的核心考点&#xff0c;尤其围绕 setTimeout、Promise.then、async/await 的执行逻辑&#xff0c;我会从概念定义、执行机制到经典例题&#xff0c;帮你彻底理清。一、…

作者头像 李华
网站建设 2026/3/15 13:06:39

【计算机毕业设计案例】基于Spring Boot的数字乡村治理系统“村事通”设计与实现基于springboot的村务管理系统的设计与实现(程序+文档+讲解+定制)

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

作者头像 李华
网站建设 2026/3/15 23:41:35

【译】GitHub Copilot for Azure(预览版)已经在 Visual Studio 2022 中推出

目录 公开预览版中有什么&#xff1f; 开始使用 先决条件 安装并设置 试试这些示例提示词 接下来是什么&#xff1f; 适用于 Azure 的 GitHub Copilot 扩展现已在 Visual Studio 2022&#xff08;17.14及以上版本&#xff09;中进入公开预览阶段。它通过 Azure MCP 服务器…

作者头像 李华
网站建设 2026/3/24 15:18:57

Java毕设项目推荐-基于Springboot的乡政府管理系统设计与实现基于springboot的村务管理系统的设计与实现【附源码+文档,调试定制服务】

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

作者头像 李华
网站建设 2026/3/15 23:41:33

2025冬至继上

如果把生活类比成可迭代的对象&#xff0c;我的生活又到哪个版本了&#xff1f;还有什么可优化的地方吗&#xff1f;客观的事物不以人的意志为转移&#xff0c;怎么才能使自己的生活贴近事物发展的自然规律&#xff0c;使自己更贴近 按规律办事&#xff1f;古人云&#xff0c;头…

作者头像 李华