当前位置: 首页 > 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;三层体系结构…...

Python爬虫实战:研究MechanicalSoup库相关技术

一、MechanicalSoup 库概述 1.1 库简介 MechanicalSoup 是一个 Python 库,专为自动化交互网站而设计。它结合了 requests 的 HTTP 请求能力和 BeautifulSoup 的 HTML 解析能力,提供了直观的 API,让我们可以像人类用户一样浏览网页、填写表单和提交请求。 1.2 主要功能特点…...

深入浅出Asp.Net Core MVC应用开发系列-AspNetCore中的日志记录

ASP.NET Core 是一个跨平台的开源框架&#xff0c;用于在 Windows、macOS 或 Linux 上生成基于云的新式 Web 应用。 ASP.NET Core 中的日志记录 .NET 通过 ILogger API 支持高性能结构化日志记录&#xff0c;以帮助监视应用程序行为和诊断问题。 可以通过配置不同的记录提供程…...

synchronized 学习

学习源&#xff1a; https://www.bilibili.com/video/BV1aJ411V763?spm_id_from333.788.videopod.episodes&vd_source32e1c41a9370911ab06d12fbc36c4ebc 1.应用场景 不超卖&#xff0c;也要考虑性能问题&#xff08;场景&#xff09; 2.常见面试问题&#xff1a; sync出…...

C++初阶-list的底层

目录 1.std::list实现的所有代码 2.list的简单介绍 2.1实现list的类 2.2_list_iterator的实现 2.2.1_list_iterator实现的原因和好处 2.2.2_list_iterator实现 2.3_list_node的实现 2.3.1. 避免递归的模板依赖 2.3.2. 内存布局一致性 2.3.3. 类型安全的替代方案 2.3.…...

【Go】3、Go语言进阶与依赖管理

前言 本系列文章参考自稀土掘金上的 【字节内部课】公开课&#xff0c;做自我学习总结整理。 Go语言并发编程 Go语言原生支持并发编程&#xff0c;它的核心机制是 Goroutine 协程、Channel 通道&#xff0c;并基于CSP&#xff08;Communicating Sequential Processes&#xff0…...

DIY|Mac 搭建 ESP-IDF 开发环境及编译小智 AI

前一阵子在百度 AI 开发者大会上&#xff0c;看到基于小智 AI DIY 玩具的演示&#xff0c;感觉有点意思&#xff0c;想着自己也来试试。 如果只是想烧录现成的固件&#xff0c;乐鑫官方除了提供了 Windows 版本的 Flash 下载工具 之外&#xff0c;还提供了基于网页版的 ESP LA…...

Neo4j 集群管理:原理、技术与最佳实践深度解析

Neo4j 的集群技术是其企业级高可用性、可扩展性和容错能力的核心。通过深入分析官方文档,本文将系统阐述其集群管理的核心原理、关键技术、实用技巧和行业最佳实践。 Neo4j 的 Causal Clustering 架构提供了一个强大而灵活的基石,用于构建高可用、可扩展且一致的图数据库服务…...

AspectJ 在 Android 中的完整使用指南

一、环境配置&#xff08;Gradle 7.0 适配&#xff09; 1. 项目级 build.gradle // 注意&#xff1a;沪江插件已停更&#xff0c;推荐官方兼容方案 buildscript {dependencies {classpath org.aspectj:aspectjtools:1.9.9.1 // AspectJ 工具} } 2. 模块级 build.gradle plu…...

AI,如何重构理解、匹配与决策?

AI 时代&#xff0c;我们如何理解消费&#xff1f; 作者&#xff5c;王彬 封面&#xff5c;Unplash 人们通过信息理解世界。 曾几何时&#xff0c;PC 与移动互联网重塑了人们的购物路径&#xff1a;信息变得唾手可得&#xff0c;商品决策变得高度依赖内容。 但 AI 时代的来…...

代码随想录刷题day30

1、零钱兑换II 给你一个整数数组 coins 表示不同面额的硬币&#xff0c;另给一个整数 amount 表示总金额。 请你计算并返回可以凑成总金额的硬币组合数。如果任何硬币组合都无法凑出总金额&#xff0c;返回 0 。 假设每一种面额的硬币有无限个。 题目数据保证结果符合 32 位带…...