news 2026/4/23 13:13:46

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/23 9:43:57

计算机Java毕设实战-基于springboot的幼儿园管理系统的设计与实现基于Springboot+vue的幼儿园管理系统设计与实现【完整源码+LW+部署说明+演示视频,全bao一条龙等】

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

作者头像 李华
网站建设 2026/4/23 11:22:15

Java毕设项目推荐-基于SpringBoot+Vue游泳用品专卖店商城平台设计与实现基于springboot的游泳用品专卖店系统的设计与实现【附源码+文档,调试定制服务】

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

作者头像 李华
网站建设 2026/4/23 11:22:17

Web前端入门第 89 问:总结 8 种跨域通信处理方案

首先跨域问题是由于浏览器的同源策略&#xff08;Same-Origin Policy&#xff09;导致的&#xff0c;基本上所有浏览器都有限制&#xff0c;默认情况是不允许跨域访问的&#xff01;&#xff01;APP 的请求不受浏览器的同源策略限制&#xff0c;所以不存在跨域。类似一个服务器…

作者头像 李华
网站建设 2026/4/23 13:02:06

《手搓》线程池优化的追求

一、先回顾一下以前《手搓》线程池CaseConcurrencyLevel设置为10并发实现了完美的指数递进关系当时内心还是得到了很大的满足第一批01:58:55.832是1个并发第二批01:58:55.944是2个并发第三批01:58:56.054是4个并发第四批01:58:56.165是8个并发01:58:56.276及以后一段时间达到并…

作者头像 李华
网站建设 2026/4/23 11:20:31

磁盘格式化和LVM挂载

磁盘格式化&#xff08;其实可以不分区直接格式化&#xff0c;为了系统操作安全使用先分区再格式化&#xff0c;直接格式化磁盘就固定只能使用一个文件系统&#xff0c;但是我们如果把所有空间都分配到了一个分区&#xff0c;那其实都一样的&#xff0c;所以分不分区其实无所谓…

作者头像 李华
网站建设 2026/4/23 11:22:27

zyyyyy

1.# 位运算&#xff1a;计算56和-18的所有位运算结果 # 注意&#xff1a;在计算机中&#xff0c;负数用补码表示 # 原值 a 56 # 正数56 b -18 # 负数-18 print("原始值:") print(f"56的二进制(原码): 00111000") print(f"-18的二进制(原码): 1…

作者头像 李华