当前位置: 首页 > news >正文

微服务知识03

1、ES搜索引擎,高性能的分布式搜索引擎,底层基于Lucene

主要用于应用程序中的搜索系统

日志收集

2、基础概念

3、ES处理流程

5、下载中文分词器

Releases · infinilabs/analysis-ik · GitHub

6、分词模式

最细粒度拆分、智能分词

7、Elaticsearch配置流程

(1)把文件拖进去,然后执行

(2)访问Elastic

8、分词器

 9、客户端集成的三种方式(第二种用的多)

​​​​​​​

10、es返回的是对象本身,更新本质是保存的操作

11、statement模式默认值丢失、row模式不会、智能模式

12、Query 复杂查询(用第三个)

13、ES语法

查询所有行跟列

MatchAllQueryBuilder

过滤行   

限定符

逻辑

 must()   and   should()  or

模糊查询

WildcardQueryBuilder

精确查询

MatchPhraseQueryBuilder

范围判断 between and

RangeQueryBuilder,gt、lt、gte

包含 in

分组统计

 排序

权重

综合排序

    @Testpublic void search(){//查询所有MatchAllQueryBuilder matchAllQueryBuilder = QueryBuilders.matchAllQuery();//分页NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(matchAllQueryBuilder);nativeSearchQuery.setPageable(PageRequest.of(0,100));SearchHits<EsProduct> searchHits = elasticsearchRestTemplate.search(nativeSearchQuery, EsProduct.class);List<EsProduct> esProducts = searchHits.stream().map(SearchHit::getContent).collect(Collectors.toList());log.info(esProducts.toString());}

14、模糊查询

? 单个单词* 匹配多个
​​​​​​​匹配的内容如果是多个中文
多个中文单词匹配在查询字段后面使用.keyword

15、ES使用流程(先部署上去7)

(1)导包

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-elasticsearch</artifactId></dependency>

(2)配置

server:port: 8081
spring:elasticsearch:uris: "http://129.204.151.181:9200"username: ""password: ""connection-timeout: 2s

(3)写实体类

package com.smart.community.es.entity;import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;import java.math.BigDecimal;
import java.util.List;/*** @author liuhuitang*/
@Data
@Document(indexName = "product_index")
public class EsProduct {@Idprivate Long productId;@Field(value = "product_name",analyzer = "ik_smart",searchAnalyzer = "ik_smart")private String productName;@Fieldprivate BigDecimal productPrice;private List<String> imageUrls;@Field(value = "shop_name",analyzer = "ik_smart",searchAnalyzer = "ik_smart")private String shopName;private Long shopId;}

(4)ProductVo(没用上)

package com.smart.community.es.common.vo;import lombok.Data;import java.math.BigDecimal;
import java.util.List;/*** @author liuhuitang*/
@Data
public class ProductVo {private String productName;private BigDecimal productPrice;private List<String> imageUrls;}

(5)EsProductDao层

package com.smart.community.es.dao;import com.smart.community.es.entity.EsProduct;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.stereotype.Repository;/*** 创建数据库* @author liuhuitang*/public interface EsProductDao {@Query("/product_product/product/1")EsProduct save(EsProduct esProduct);EsProduct update(EsProduct esProduct);}
package com.smart.community.es.dao.impl;import com.smart.community.es.dao.EsProductDao;
import com.smart.community.es.entity.EsProduct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.stereotype.Repository;/*** @author liuhuitang*/
@Repository
public class EsProductDaoImpl implements EsProductDao {@Autowiredprivate ElasticsearchRestTemplate restTemplate;@Overridepublic EsProduct save(EsProduct esProduct) {return restTemplate.save(esProduct);}@Overridepublic EsProduct update(EsProduct esProduct) {return null;}
}

(6)测试

package com.smart.community.es.dao.impl;import cn.hutool.core.util.RandomUtil;
import com.smart.community.es.dao.EsProductDao;
import com.smart.community.es.entity.EsProduct;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;import static org.junit.jupiter.api.Assertions.*;@SpringBootTest
class EsProductDaoImplTest {@Autowiredprivate EsProductDao productDao;@Autowiredprivate ElasticsearchRestTemplate restTemplate;@Testvoid save() {EsProduct esProduct = new EsProduct();esProduct.setProductId(1L);esProduct.setProductName("测试商品");esProduct.setProductPrice(new BigDecimal("1.00"));esProduct.setShopId(100L);esProduct.setShopName("测试店铺");productDao.save(esProduct);}/*** 生成100条测试数据并保存*/@Testvoid batchSave(){List<EsProduct> products = Stream.generate(RandomUtil::randomInt).limit(100).map(id -> {EsProduct esProduct = new EsProduct();esProduct.setProductId(Long.valueOf(id));esProduct.setProductName("测试商品" + id);esProduct.setShopName("测试店铺" + id);BigDecimal randomPrice = RandomUtil.randomBigDecimal(BigDecimal.ZERO, new BigDecimal("100000000.00"));esProduct.setProductPrice(randomPrice.setScale(2, RoundingMode.HALF_UP));esProduct.setShopId(1L);return esProduct;}).collect(Collectors.toList());restTemplate.save(products);}}
package com.qf.cloud.es.dao.impl;import com.qf.cloud.es.entity.EsProduct;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.index.query.*;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.SearchHit;
import org.springframework.data.elasticsearch.core.SearchHits;
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;@SpringBootTest
@Slf4j
public class ElasticsearchRestTemplateTest {@ResourceElasticsearchRestTemplate elasticsearchRestTemplate;/*** 查询  search* NativeSearchQuery  复杂的查询* 查询所有行跟列* 过滤行   限定符     逻辑   模糊查询   精确查询  范围判断 between   and    包含 in* 分组统计* 排序    权重   综合排序* match_all* <p>* 过滤列*/@Testpublic void search() {MatchAllQueryBuilder matchAllQueryBuilder = QueryBuilders.matchAllQuery();NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(matchAllQueryBuilder);nativeSearchQuery.setPageable(PageRequest.of(1, 100));SearchHits<EsProduct> searchHits = elasticsearchRestTemplate.search(nativeSearchQuery, EsProduct.class);List<EsProduct> esProducts = searchHits.stream().map(SearchHit::getContent).collect(Collectors.toList());log.info(esProducts.toString());}/*** 返回查询*/@Testpublic void testRangeQueryBuilder() {/***  gt >   <  lt  >= gte <= lte* between  and*/RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery("productId");rangeQueryBuilder.gt(10);NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(rangeQueryBuilder);SearchHits<EsProduct> searchHits = elasticsearchRestTemplate.search(nativeSearchQuery, EsProduct.class);List<EsProduct> esProducts = searchHits.stream().map(SearchHit::getContent).collect(Collectors.toList());log.info(esProducts.toString());}/***  通配符*  ? 单个单词*  * 匹配多个**  匹配的内容的多个中文*  多个中文单词匹配在查询字段后面使用.keyword*//*** 模糊查询*/@Testpublic void testWildcardQuery() {WildcardQueryBuilder wildcardQuery = QueryBuilders.wildcardQuery("product_name.keyword", "*测试*");NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(wildcardQuery);SearchHits<EsProduct> searchHits = elasticsearchRestTemplate.search(nativeSearchQuery, EsProduct.class);List<EsProduct> esProducts = searchHits.stream().map(SearchHit::getContent).collect(Collectors.toList());log.info(esProducts.toString());}/*** =*/@Testpublic void testMatchPhraseQueryBuilder() {/***  通配符*  ? 单个单词*  * 匹配多个**  匹配的内容的多个中文*  多个中文单词匹配在查询字段后面使用.keyword*/MatchPhraseQueryBuilder matchPhraseQueryBuilder = QueryBuilders.matchPhraseQuery("shop_name", "测试");NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(matchPhraseQueryBuilder);SearchHits<EsProduct> searchHits = elasticsearchRestTemplate.search(nativeSearchQuery, EsProduct.class);List<EsProduct> esProducts = searchHits.stream().map(SearchHit::getContent).collect(Collectors.toList());log.info(esProducts.toString());}/*** 逻辑 and or* <p>* 查询商品信息以及id小于等于 1* BoolQueryBui

相关文章:

微服务知识03

1、ES搜索引擎,高性能的分布式搜索引擎,底层基于Lucene 主要用于应用程序中的搜索系统 日志收集 2、基础概念 3、ES处理流程 5、下载中文分词器 Releases infinilabs/analysis-ik GitHub 6、分词模式 最细粒度拆分、智能分词 7、Elaticsearch配置流程 (1)把文件拖进…...

JPEG照片被误删除如何恢复?学会这个方法就够了

JPG/JPEG是一种后缀名为“.jpg”或“.jpeg”的图形格式。它是存储照片图像的常用格式&#xff0c;因此我们可以使用数码相机、手机或其他设备来获取大量的JPG/JPEG文件。有时&#xff0c;我们会遇到由于意外删除、格式化驱动器或其他未知原因导致 JPEG 文件丢失的情况。无论哪种…...

红黑树的学习

红黑树 红黑树出自一种平衡的二叉查找树&#xff0c;是计算机科学中中用到的一种数据结构 1972年出现&#xff0c;当时被称之为平衡二叉B树。后来&#xff0c;1978年被修改为如今的红黑树 他是一种特殊的二叉查找树&#xff0c;红黑树的每一个节点上都有存储表示节点的颜色 …...

C# OpenCvSharp DNN FreeYOLO 人脸检测

目录 效果 模型信息 项目 代码 下载 C# OpenCvSharp DNN FreeYOLO 人脸检测 效果 模型信息 Inputs ------------------------- name&#xff1a;input tensor&#xff1a;Float[1, 3, 192, 320] --------------------------------------------------------------- Outp…...

单例九品--第五品

单例九品--第五品 上一品引入写在前边代码部分1代码部分2实现方式评注与思考下一品的设计思考 上一品引入 第四品中可能会因为翻译单元的链接先后顺序&#xff0c;造成静态初始化灾难的问题。造成的原因是因为存在调用单例对象前没有完成定义的问题&#xff0c;这一品将着重解…...

Lwip之TCP服务端示例记录(1对多)

前言 实现多个客户端同时连接初步代码结构已经实现完成(通过轮训的方式) // // Created by shchl on 2024/3/8. // #if 1#include <string.h> #include "lwip/api.h" #include "FreeRTOS.h" #include "task.h" #include "usart.h&…...

哲理:为什么你要学习编程这项技能

有一家饭店的大厨&#xff0c;烧得一手好菜&#xff0c;经过口碑相传&#xff0c;客人从五湖四海闻名而来。然而这对饭店的老板来说&#xff0c;并不单纯是一个好消息。因为客人不是奔着饭店&#xff0c;而是奔着大厨的手艺来的。老板必须想办法留住这位大厨&#xff0c;否则他…...

【机器学习300问】30、准确率的局限性在哪里?

一、什么是准确率&#xff1f; 在解答这个问题之前&#xff0c;我们首先得先回顾一下准确率的定义&#xff0c;准确率是机器学习分类问题中一个很直观的指标&#xff0c;它告诉我们模型正确预测的比例&#xff0c;即 还是用我最喜欢的方式&#xff0c;举例子来解释一下&#xf…...

融资项目——网关微服务

1. 网关的路由转发功能 在前后端分离的项目中&#xff0c;网关服务可以将前端的相关请求转发到相应的后端微服务中。 2. 网关微服务的配置 首先需要创建一个网关微服务&#xff0c;并添加依赖。 <!-- 网关 --><dependency><groupId>org.springframework.cl…...

飞驰云联CEO朱旭光荣获“科技领军人才”称号

2024年2月29日&#xff0c;苏州工业园区“优化营商环境暨作风效能建设大会”成功举办&#xff0c;会上公布了2023年度苏州工业园区第十七届第一批金鸡湖科技领军人才名单&#xff0c;Ftrans飞驰云联创始人兼CEO朱旭光先生凭借在数据安全以及文件交换领域取得的突出成果&#xf…...

Dockerfile的使用,怎样制作镜像

Docker 提供了一种更便捷的方式&#xff0c;叫作 Dockerfile docker build命令用于根据给定的Dockerfile构建Docker镜像。 docker build命令参数&#xff1a; --build-arg&#xff0c;设置构建时的变量 --no-cache&#xff0c;默认false。设置该选项&#xff0c;将不使用Build …...

外包干了5天,技术退步明显。。。。。

在湖南的一个安静角落&#xff0c;我&#xff0c;一个普通的大专生&#xff0c;开始了我的软件测试之旅。四年的外包生涯&#xff0c;让我在舒适区里逐渐失去了锐气&#xff0c;技术停滞不前&#xff0c;仿佛被时间遗忘。然而&#xff0c;生活的转机总是在不经意间降临。 与女…...

leetcode2834--找出美丽数组的最小和

1. 题意 求一个序列和。序列 a a a满足&#xff1a; 大小为 n n n ∀ 0 ≤ i , j < n , i ≠ j , a i a j ≠ t a r g e t \forall 0\le i,j \lt n,i \ne j,a_ia_j \ne target ∀0≤i,j<n,ij,ai​aj​target 找出美丽数组的最小和 2. 题解 贪心的构造这个序列。…...

【NR 定位】3GPP NR Positioning 5G定位标准解读(七)- GNSS定位方法

前言 3GPP NR Positioning 5G定位标准&#xff1a;3GPP TS 38.305 V18 3GPP 标准网址&#xff1a;Directory Listing /ftp/ 【NR 定位】3GPP NR Positioning 5G定位标准解读&#xff08;一&#xff09;-CSDN博客 【NR 定位】3GPP NR Positioning 5G定位标准解读&#xff08;…...

结构体和malloc学习笔记

结构体学习&#xff1a; 为什么会出现结构体&#xff1a; 为了表示一些复杂的数据&#xff0c;而普通的基本类型变量无法满足要求&#xff1b; 定义&#xff1a; 结构体是用户根据实际需要自己定义的符合数类型&#xff1b; 如何使用结构体&#xff1a; //定义结构体 struc…...

Nginx常用命令总结及常见问题排查

连续更新挑战第4天… 目录 常用启停命令Nginx 常见问题Nginx 如何忽略非标准http头检测?Nginx websocket代理Nginx 临时缓存不够导致下载文件失败Nginx 没有临时缓存目录权限导致下载文件失败Nginx非root用户启动无法使用80端口或者报无权限异常路由重写怎么配置?nginx 根据…...

微服务超大Excel文件导出方案优化

1、在导出Excel时经常会碰到文件过大&#xff0c;导出特别慢 2、微服务限制了请求超时时间&#xff0c;文件过大情况必然超时 优化思路&#xff1a; 1、文件过大时通过文件拆分、打包压缩zip&#xff0c;然后上传到oss,并设置有效期&#xff08;30天过期&#xff09; 2、把…...

论文阅读之Multimodal Chain-of-Thought Reasoning in Language Models

文章目录 简介摘要引言多模态思维链推理的挑战多模态CoT框架多模态CoT模型架构细节编码模块融合模块解码模块 实验结果总结 简介 本文主要对2023一篇论文《Multimodal Chain-of-Thought Reasoning in Language Models》主要内容进行介绍。 摘要 大型语言模型&#xff08;LLM…...

灯塔:CSS笔记(2)

一 选择器进阶 后代选择器&#xff1a;空格 作用&#xff1a;根据HTML标签的嵌套关系&#xff0c;&#xff0c;选择父元素 后代中满足条件的元素 选择器语法&#xff1a;选择器1 选择器2{ css } 结果&#xff1a; *在选择器1所找到标签的后代&#xff08;儿子 孙子 重孙子…...

基于Springboot的志愿服务管理系统(有报告)。Javaee项目,springboot项目。

演示视频&#xff1a; 基于Springboot的志愿服务管理系统&#xff08;有报告&#xff09;。Javaee项目&#xff0c;springboot项目。 项目介绍&#xff1a; 采用M&#xff08;model&#xff09;V&#xff08;view&#xff09;C&#xff08;controller&#xff09;三层体系结构…...

谷歌浏览器插件

项目中有时候会用到插件 sync-cookie-extension1.0.0&#xff1a;开发环境同步测试 cookie 至 localhost&#xff0c;便于本地请求服务携带 cookie 参考地址&#xff1a;https://juejin.cn/post/7139354571712757767 里面有源码下载下来&#xff0c;加在到扩展即可使用FeHelp…...

Xshell远程连接Kali(默认 | 私钥)Note版

前言:xshell远程连接&#xff0c;私钥连接和常规默认连接 任务一 开启ssh服务 service ssh status //查看ssh服务状态 service ssh start //开启ssh服务 update-rc.d ssh enable //开启自启动ssh服务 任务二 修改配置文件 vi /etc/ssh/ssh_config //第一…...

C/C++ 中附加包含目录、附加库目录与附加依赖项详解

在 C/C 编程的编译和链接过程中&#xff0c;附加包含目录、附加库目录和附加依赖项是三个至关重要的设置&#xff0c;它们相互配合&#xff0c;确保程序能够正确引用外部资源并顺利构建。虽然在学习过程中&#xff0c;这些概念容易让人混淆&#xff0c;但深入理解它们的作用和联…...

Python Einops库:深度学习中的张量操作革命

Einops&#xff08;爱因斯坦操作库&#xff09;就像给张量操作戴上了一副"语义眼镜"——让你用人类能理解的方式告诉计算机如何操作多维数组。这个基于爱因斯坦求和约定的库&#xff0c;用类似自然语言的表达式替代了晦涩的API调用&#xff0c;彻底改变了深度学习工程…...

Cilium动手实验室: 精通之旅---13.Cilium LoadBalancer IPAM and L2 Service Announcement

Cilium动手实验室: 精通之旅---13.Cilium LoadBalancer IPAM and L2 Service Announcement 1. LAB环境2. L2公告策略2.1 部署Death Star2.2 访问服务2.3 部署L2公告策略2.4 服务宣告 3. 可视化 ARP 流量3.1 部署新服务3.2 准备可视化3.3 再次请求 4. 自动IPAM4.1 IPAM Pool4.2 …...

AxureRP-Pro-Beta-Setup_114413.exe (6.0.0.2887)

Name&#xff1a;3ddown Serial&#xff1a;FiCGEezgdGoYILo8U/2MFyCWj0jZoJc/sziRRj2/ENvtEq7w1RH97k5MWctqVHA 注册用户名&#xff1a;Axure 序列号&#xff1a;8t3Yk/zu4cX601/seX6wBZgYRVj/lkC2PICCdO4sFKCCLx8mcCnccoylVb40lP...

FTXUI::Dom 模块

DOM 模块定义了分层的 FTXUI::Element 树&#xff0c;可用于构建复杂的终端界面&#xff0c;支持响应终端尺寸变化。 namespace ftxui {...// 定义文档 定义布局盒子 Element document vbox({// 设置文本 设置加粗 设置文本颜色text("The window") | bold | color(…...

大模型真的像人一样“思考”和“理解”吗?​

Yann LeCun 新研究的核心探讨&#xff1a;大语言模型&#xff08;LLM&#xff09;的“理解”和“思考”方式与人类认知的根本差异。 核心问题&#xff1a;大模型真的像人一样“思考”和“理解”吗&#xff1f; 人类的思考方式&#xff1a; 你的大脑是个超级整理师。面对海量信…...

Git 命令全流程总结

以下是从初始化到版本控制、查看记录、撤回操作的 Git 命令全流程总结&#xff0c;按操作场景分类整理&#xff1a; 一、初始化与基础操作 操作命令初始化仓库git init添加所有文件到暂存区git add .提交到本地仓库git commit -m "提交描述"首次提交需配置身份git c…...

OpenGL-什么是软OpenGL/软渲染/软光栅?

‌软OpenGL&#xff08;Software OpenGL&#xff09;‌或者软渲染指完全通过CPU模拟实现的OpenGL渲染方式&#xff08;包括几何处理、光栅化、着色等&#xff09;&#xff0c;不依赖GPU硬件加速。这种模式通常性能较低&#xff0c;但兼容性极强&#xff0c;常用于不支持硬件加速…...