news 2026/2/12 13:35:23

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/2/5 7:46:44

AI大模型学习全攻略:从零基础到项目实战的完整路径与资源指南_AGI大模型面经汇总

文章分享了多位求职者的大模型算法实习面试经验&#xff0c;并详细介绍了AI大模型的学习路线和资源。学习路径分为七个阶段&#xff1a;系统设计、提示词工程、平台应用开发、知识库应用、微调开发、多模态应用和行业应用。提供了大模型学习思维导图、书籍手册、视频教程等资料…

作者头像 李华
网站建设 2026/2/6 5:53:45

2025.12.15-2025.12.21:课题分离

&#x1f31f; 本周完成的3件亮点事情&#xff08;可具体写过程&#xff09;&#xff1a; R7终于还是跑起来了&#xff0c;自己也克服了内耗。问了jingle&#xff0c;chennuo&#xff0c;包括yunkai&#xff0c;我跟人交流慢慢变多了&#xff0c;也不太担心别人的看法了。这是阿…

作者头像 李华
网站建设 2026/2/3 10:56:54

.NET Core API 性能优化实战:从 100 QPS 到 10,000 QPS 的进化之路

目录 1. 接口性能优化 ✅ 使用异步编程 ✅ 启用响应压缩 2. 数据库访问优化 ✅ 使用连接池 ✅ 减少 N1 查询 ✅ 使用缓存 3. 网络调用优化 ✅ 正确使用 HttpClient ✅ 添加超时 & 重试策略 4. 缓存与限流 ✅ 使用内存缓存 (MemoryCache) ✅ 使用分布式缓存 (R…

作者头像 李华
网站建设 2026/2/8 10:37:42

Eino大模型智能体框架全解析:从原理到部署,助你快速上手AI应用

Eino是字节跳动开源的大模型智能体框架&#xff0c;采用分层架构设计&#xff0c;提供智能体引擎、模型适配器等核心组件&#xff0c;支持多模型集成、工具调用和流式处理。文章通过智能客服和代码审查助手案例展示实际应用&#xff0c;并详细介绍性能优化、错误处理和监控等最…

作者头像 李华
网站建设 2026/2/10 2:54:09

RAG架构的冰山真相——准确率之外的6个关键决策指标

本文深入剖析RAG架构评估中的"冰山现象"&#xff1a;供应商过度宣传准确率指标&#xff0c;却隐藏延迟、成本、效率等关键运营数据。文章对比了向量RAG、推理型RAG、GraphRAG和LightRAG等架构的优缺点&#xff0c;指出当前基准测试体系的局限性&#xff0c;并提出了从…

作者头像 李华
网站建设 2026/2/6 6:44:38

非遗手作带货AI视频制作,快速起量(附万能提示词)

大家好&#xff0c;我是AI培训韩老师写在开头我一直坚信“垂直领域AI”是普通人逆袭的黄金组合&#xff0c;AI电商的核心就是用技术降低创作门槛、提升转化效率。今天要分享的是非遗手作类电商的实操玩法——粉丝亲测的账号&#xff0c;靠非遗传承人带货视频&#xff0c;在抖音…

作者头像 李华