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

ES8的Java API client 8.0 简单示例操作 Elasticsearch

1.加入依赖

      <dependency><groupId>co.elastic.clients</groupId><artifactId>elasticsearch-java</artifactId><version>8.12.2</version></dependency>

2.配置类

@Slf4j
@Configuration
public class ElasticSearchConfig {@Value("${elasticsearch.hosts}")private String hosts;@Value("${elasticsearch.port}")private int port;@Value("${elasticsearch.username}")private String username;@Value("${elasticsearch.password}")private String password;@Value("${elasticsearch.apikey:''}")private String apikey;/*** 单节点没密码连接** @return*/@Beanpublic ElasticsearchClient elasticsearchClient() {String[] servers = hosts.split(",");int len = servers.length;if (0 == len) {log.error("ElasticsearchClient 配置错误!");}ElasticsearchTransport transport = null;// 不是集群时if (1 == len) {// 无账号、密码if (StringUtils.isEmpty(username) && StringUtils.isEmpty(password)) {RestClient client = RestClient.builder(new HttpHost(servers[0], port, "http")).setHttpClientConfigCallback(httpClientBuilder->httpClientBuilder.setDefaultHeaders(Collections.singletonList(new BasicHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString()))).addInterceptorLast((HttpResponseInterceptor) (response, context)-> response.addHeader("X-Elastic-Product", "Elasticsearch"))).build();transport = new RestClientTransport(client, new JacksonJsonpMapper());} else {// 账号密码的配置final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));// 自签证书的设置,并且还包含了账号密码RestClientBuilder.HttpClientConfigCallback callback = httpAsyncClientBuilder -> httpAsyncClientBuilder.setDefaultCredentialsProvider(credentialsProvider).addInterceptorLast((HttpResponseInterceptor)(response, context) ->response.addHeader("X-Elastic-Product", "Elasticsearch"));RestClient client = RestClient.builder(new HttpHost(servers[0], port, "http")).setHttpClientConfigCallback(callback).build();transport = new RestClientTransport(client, new JacksonJsonpMapper());}} else {// 集群时无账号、密码if (StringUtils.isEmpty(username) && StringUtils.isEmpty(password)) {transport = getElasticsearchTransport(toHttpHost());} else {transport = getElasticsearchTransport(username, password, toHttpHost());}}return new ElasticsearchClient(transport);}private HttpHost[] toHttpHost() {if (hosts.split(",").length == 0) {throw new RuntimeException("invalid elasticsearch configuration");}String[] hostArray = hosts.split(",");HttpHost[] httpHosts = new HttpHost[hostArray.length];HttpHost httpHost;for (int i = 0; i < hostArray.length; i++) {String[] strings = hostArray[i].split(":");httpHost = new HttpHost(strings[0], Integer.parseInt(strings[1]), "http");httpHosts[i] = httpHost;}return httpHosts;}private static ElasticsearchTransport getElasticsearchTransport(String username, String password, HttpHost... hosts) {// 账号密码的配置final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));// 自签证书的设置,并且还包含了账号密码RestClientBuilder.HttpClientConfigCallback callback = httpAsyncClientBuilder -> httpAsyncClientBuilder.setSSLContext(buildSSLContext()).setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).setDefaultCredentialsProvider(credentialsProvider).setDefaultHeaders(Stream.of(new BasicHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString())).collect(toList())).addInterceptorLast((HttpResponseInterceptor)(response, context) ->response.addHeader("X-Elastic-Product", "Elasticsearch")).addInterceptorLast((HttpResponseInterceptor) (response, context)-> response.addHeader("X-Elastic-Product", "Elasticsearch"));// 用builder创建RestClient对象RestClient client = RestClient.builder(hosts).setHttpClientConfigCallback(callback).build();return new RestClientTransport(client, new JacksonJsonpMapper());}private static ElasticsearchTransport getElasticsearchTransport(HttpHost... hosts) {// 用builder创建RestClient对象RestClient client = RestClient.builder(hosts).build();return new RestClientTransport(client, new JacksonJsonpMapper());}private static SSLContext buildSSLContext() {ClassPathResource resource = new ClassPathResource("es01.crt");SSLContext sslContext = null;try {CertificateFactory factory = CertificateFactory.getInstance("X.509");Certificate trustedCa;try (InputStream is = resource.getInputStream()) {trustedCa = factory.generateCertificate(is);}KeyStore trustStore = KeyStore.getInstance("pkcs12");trustStore.load(null, null);trustStore.setCertificateEntry("ca", trustedCa);SSLContextBuilder sslContextBuilder = SSLContexts.custom().loadTrustMaterial(trustStore, null);sslContext = sslContextBuilder.build();} catch (CertificateException | IOException | KeyStoreException | NoSuchAlgorithmException |KeyManagementException e) {log.error("ES连接认证失败", e);}return sslContext;}
}

3.相关api

前提:

注入ElasticsearchClient

@Autowired
private ElasticsearchClient client;

3.1 创建索引

 public void createIndex() throws IOException {ElasticsearchIndicesClient indices = client.indices();//是否存在//1.lambdaboolean isExit = indices.exists(req -> req.index("ttt")).value();//2.builder,ofExistsRequest existsRequestOf = ExistsRequest.of(req -> req.index("ttt"));ExistsRequest existsRequest = new ExistsRequest.Builder().index("ttt").build();boolean builderExist = indices.exists(existsRequest).value();if (isExit){log.info("已经存在ttt");}else {//1.lambdaboolean isSuccess = indices.create(req -> req.index("ttt")).acknowledged();//2.builder,ofCreateIndexRequest createIndexRequestOf = CreateIndexRequest.of(req -> req.index("ttt"));CreateIndexRequest createIndexRequest = new CreateIndexRequest.Builder().index("ttt").build();boolean buildIsSuccess = indices.create(createIndexRequest).acknowledged();if (isSuccess){log.info("创建成功");}else {log.info("创建失败");}}}

3.2 删除索引

public void deleteIndex() throws IOException {//1.lambdaboolean isSuccess = client.indices().delete(req -> req.index("ttt")).acknowledged();//2.builder,ofDeleteIndexRequest deleteRequestOf = DeleteIndexRequest.of(req -> req.index("ttt"));DeleteIndexRequest deleteRequest = new DeleteIndexRequest.Builder().index("ttt").build();boolean buildDeleteRequest = client.indices().delete(deleteRequest).acknowledged();}

3.3查询索引

 public void queryIndex() throws IOException {//1.lambda//查询单个Map<String, IndexState> tttIndex = client.indices().get(req -> req.index("ttt")).result();//查询索引Set<String> all = client.indices().get(req -> req.index("*")).result().keySet();//2.builderGetIndexRequest getIndexRequestOf = GetIndexRequest.of(req -> req.index("ttt"));GetIndexRequest getIndexRequest = new GetIndexRequest.Builder().index("ttt").build();Map<String, IndexState> result = client.indices().get(getIndexRequest).result();}

3.4 插入文档

 public void addDoc() throws IOException {Goods goods = new Goods("3212334","华为mate60", 9999.0);//1.lambdaclient.index(i->i.index("goods").id(goods.getSku()).document(goods));//2.builder-ofIndexRequest<Goods> addIndexRequestOf = IndexRequest.of(t -> t.id(goods.getSku()).document(goods).index("goods"));IndexRequest<Goods> addIndexRequest = new IndexRequest<>.Builder().index("goods").id(goods.getSku()).document(goods).build();IndexResponse index = client.index(addIndexRequest);}

3.5 批量插入文档

public void addBatchDoc() throws IOException {List<Goods> goodsList = List.of(new Goods("1","手机",999.0));BulkRequest.Builder br = new BulkRequest.Builder();for (Goods goods : goodsList) {br.operations(op->op.index(idx->idx.index("goods").id(goods.getSku()).document(goods)));}BulkResponse result = client.bulk(br.build());// Log errors, if anyif (result.errors()) {log.error("Bulk had errors");for (BulkResponseItem item: result.items()) {if (item.error() != null) {log.error(item.error().reason());}}}}

3.6查询文档

public void queryDoc() throws IOException {//1.lambdaGetResponse<Goods> response = client.get(g ->  g.index("goods").id("00000"), Goods.class);//2.builder,ofGetRequest request = GetRequest.of(g -> g.index("goods").id("00000"));GetRequest ofRequest = new GetRequest.Builder().index("goods").id("00000").build();GetResponse<Goods> response1 = client.get(request, Goods.class);if (response.found()){Goods source = response.source();System.out.println(source);}}

3.7修改文档

 public void updateDoc() throws IOException {//全量Goods goods = new Goods("1","2",3.0);UpdateResponse<Goods> update = client.update(u -> u.doc(goods).id(goods.getSku()), Goods.class);//ofUpdateRequest<Object, Object> of = UpdateRequest.of(u -> u.id(goods.getSku()).doc(goods));UpdateResponse<Object> update1 = client.update(of, Goods.class);}

3.8删除文档

   */public void deleteDoc() throws IOException {DeleteResponse goods = client.delete(d -> d.index("goods").id("0000"));//ofDeleteRequest deleteRequest = DeleteRequest.of(d -> d.index("goods").id("0000"));client.delete(deleteRequest);}

3.9 DSL 匹配查询

public void query() throws IOException {String text = "华为mate60";SearchResponse<Goods> response = client.search(s -> s.index("goods").query(q -> q.match(m -> m.field("name").query(text))), Goods.class);//ofSearchRequest request = SearchRequest.of(s -> s.index("goods").query(q -> q.match(m ->m.field("").field(""))));SearchResponse<Goods> search = client.search(request, Goods.class);//结果//总数TotalHits total = response.hits().total();assert total != null;boolean isExactResult = total.relation() == TotalHitsRelation.Eq;if (isExactResult) {log.info("找到 " + total.value() + " 个结果");} else {log.info("找到超过 " + total.value() + " 个结果");}List<Hit<Goods>> hits = response.hits().hits();for (Hit<Goods> hit : hits) {Goods goods = hit.source();System.out.println(goods);}}

3.10 多精确terms

public void terms(){List<FieldValue> v = new ArrayList<>();FieldValue tag2 = FieldValue.of("tag2");FieldValue tag1 = FieldValue.of("tag1");v.add(tag1);v.add(tag2);TermsQuery tags = TermsQuery.of(t -> t.field("tags").terms(tm -> tm.value(v)));SearchRequest of = SearchRequest.of(s -> s.index("goods").query(q -> q.bool(b -> b.must(m -> m.terms(tags)).should(sh -> sh.match(ma -> ma.field("").query(""))))).from(0).size(10));}

3.11 布尔查询

@Slf4j
@Service
public class EsTest {@Autowiredprivate ElasticsearchClient client;/*** bool*/public void boolQuery() throws IOException {Map<String, HighlightField> map = new HashMap<>();map.put("title", HighlightField.of(hf -> hf.preTags("<em>").postTags("<em/>")));map.put("description", HighlightField.of(hf -> hf.preTags("<em>").postTags("<em/>").numberOfFragments(4).fragmentSize(50)));//numberOfFragments(4),表示将字段分割为最多4个片段,并设置 fragmentSize(50),表示每个片段的大小为50个字符。Highlight highlight = Highlight.of(h -> h.type(HighlighterType.Unified).fields(map).fragmentSize(50)//设置默认的高亮片段大小为50个字符,如果字段没有单独设置,则使用此默认值。.numberOfFragments(5)//设置每个字段的最大高亮片段数为5个。);String text = "华为mate60";SearchResponse<Goods> search = client.search(s -> s.index("goods").query(q -> q.bool(b -> b.must(m -> m.term(t -> t.field("品牌").value("华为"))).should(sd -> sd.match(mh -> mh.field("name").query("mate60"))))).from(0).size(10).highlight(highlight), Goods.class);//ofSearchRequest of = SearchRequest.of(s -> s.index("goods").query(q -> q.bool(b -> b.must(m -> m.term(t -> t.field("品牌").value("华为"))).should(sh -> sh.match(ma -> ma.field("").query(""))))).from(0).size(10).highlight(highlight));SearchResponse<Goods> response = client.search(of, Goods.class);List<Hit<Goods>> hits = response.hits().hits();for (Hit<Goods> hit : hits) {Goods goods = hit.source();if (goods == null){continue;}Map<String, List<String>> highlightList = hit.highlight();highlightList.forEach((key, Value)->{if (Objects.equals(key,goods.getName())){//存入}else {//无高亮}});System.out.println(goods);}}}

3.12构建排序

/*** 构建排序*/private List<SortOptions> buildSort(SearchDTO dto) {if (dto.getTimeSort() != null){SortOptions sortOptions ;if (dto.getTimeSort() == 0){sortOptions = SortOptions.of(s -> s.field(FieldSort.of(f -> f.field(SearchConstants.TIMESTAMP).order(SortOrder.Asc))));}else {sortOptions = SortOptions.of(s -> s.field(FieldSort.of(f -> f.field(SearchConstants.TIMESTAMP).order(SortOrder.Desc))));}return List.of(sortOptions);}else {return Collections.emptyList();}}

...........

相关文章:

ES8的Java API client 8.0 简单示例操作 Elasticsearch

1.加入依赖 <dependency><groupId>co.elastic.clients</groupId><artifactId>elasticsearch-java</artifactId><version>8.12.2</version></dependency>2.配置类 Slf4j Configuration public class ElasticSearchConfig {Valu…...

多线程CompletableFuture

最近发现同事整理了一个不错的关于CompletableFuture的文档&#xff0c;在这里记录一下&#xff0c;方便以后工作备用 CompletableFuture future CompletableFuture.supplyAsync(() -> {return "开新线程异步执行"; })result future.get(); // 线程阻塞等待结果…...

AR传送门+特定区域显示内容+放大镜 效果着色器使用

AR传送门特定区域显示内容放大镜 效果 关键词&#xff1a;Portal Mask 1、教程链接&#xff1a; AR 传送门教程 Unity - Portal Mask Implementation - Part 4_哔哩哔哩_bilibili 应用案例效果&#xff1a; 2、案例下载地址&#xff1a;使用unity 2021.3.33f1 obi 工具…...

设置Hadoop守护进程的JVM参数

一般情况下我们不去动守护进程的JVM&#xff0c;这里的守护进程说的是NameNode、DataNode等Hadoop服务自己本身的进程。但是有一些特殊情况下需要限制&#xff0c;比如工作中虽然集群中资源队列会有10%左右的预留空余&#xff0c;不过这是整个集群队列的限制&#xff0c;对于Da…...

可视化大屏

可视化大屏 是一种利用计算机图形学技术&#xff0c;将复杂的数据和信息转换为直观的可视化图形&#xff0c;以呈现数据信息的工具。它不仅在电影中常见&#xff0c;而且已经实实在在地被应用在商业、金融、制造等各个行业的业务场景中&#xff0c;成为大数据分析和展示的重要工…...

pytest框架

pytest测试框架 单元测试框架定义&#xff1a;针对软件开发最小的单元&#xff08;函数&#xff0c;方法&#xff09;进行正确性位置测试 单元测试框架&#xff1a;java&#xff08;junit&#xff0c;testing&#xff09;python&#xff08;unittest&#xff0c;pytest&#…...

基于大数据的亚健康人群数据分析及可视化系统

作者&#xff1a;计算机学姐 开发技术&#xff1a;SpringBoot、SSM、Vue、MySQL、JSP、ElementUI、Python、小程序等&#xff0c;“文末源码”。 专栏推荐&#xff1a;前后端分离项目源码、SpringBoot项目源码、Vue项目源码、SSM项目源码 精品专栏&#xff1a;Java精选实战项目…...

黄金短线交易策略:波动中的高效盈利之法

今日&#xff0c;亚市盘初&#xff0c;现货黄金就高位震荡。在昨日金价再度冲高&#xff0c;一度刷新历史高点至2685.49美元&#xff0c;收报2672.25美元。其中主要原因是美国公布了最新的核心PCE&#xff08;个人消费支出&#xff09;物价指数和初请失业金人数等经济数据&…...

西陆家政系统V1.0.1

微信小程序开发的西陆家政服务管理系统小程序 V1.0.1bug修复优化 1.修复首页轮播不能自动轮播问题;2.修复订单详情价格显示问题;3.修复在开放城市模式下,其他城市可以下单问题;4.修复个人二维码跳转小程序路径异常问题;5.修复小程序编辑我的地址选择定位后不刷新问题&#xf…...

时间安全精细化管理平台/iapp/mobile/facereg/facereg.html接口存在未授权访问漏洞

漏洞描述 登录--时间&安全精细化管理平台/iapp/mobile/facereg/facereg.html接口存在未授权访问漏洞&#xff0c;黑客可以未授权等级员工信息对平台造成影响 FOFA&#xff1a; body"登录--时间&amp;安全精细化管理平台" 漏洞复现 IP/iapp/mobile/facereg…...

自动化测试实例:Web登录功能性测试(无验证码)

&#x1f345; 点击文末小卡片 &#xff0c;免费获取软件测试全套资料&#xff0c;资料在手&#xff0c;涨薪更快 一、什么是自动化测试 把人为驱动的测试行为转化为机器执行的一种过程称为自动化测试。(来自百度百科)本质上来说&#xff0c;自动化测试对比起手工测试除了需要…...

【算法篇】二叉树类(3)(笔记)

目录 一、Leetcode 题目 1. 二叉树的最近公共祖先 2. 二叉搜索树的最近公共祖先 &#xff08;1&#xff09;递归法 &#xff08;2&#xff09;迭代法 3. 二叉搜索树中的插入操作 &#xff08;1&#xff09;递归法 &#xff08;2&#xff09;迭代法 4. 删除二叉搜索树中…...

基于php的律所管理系统

作者&#xff1a;计算机学姐 开发技术&#xff1a;SpringBoot、SSM、Vue、MySQL、JSP、ElementUI、Python、小程序等&#xff0c;“文末源码”。 专栏推荐&#xff1a;前后端分离项目源码、SpringBoot项目源码、Vue项目源码、SSM项目源码 精品专栏&#xff1a;Java精选实战项目…...

MySQL 之索引详解

想象一下&#xff0c;你正在图书馆寻找一本关于 MySQL 索引的书。图书馆里有成千上万本书&#xff0c;但没有目录。你只能一排一排、一本一本地找&#xff0c;直到找到你想要的书。这将会花费大量的时间&#xff01;数据库索引就像图书馆的目录一样&#xff0c;可以帮助数据库系…...

C#测试调用FreeSpire.PDFViewer浏览PDF文件

Free Spire.PDFViewer是商业版Spire.PDFViewer的社区版本&#xff0c;支持以控件形式打开并查看PDf文件&#xff0c;但由于是免费版本&#xff0c;存在使用限制&#xff0c;打开的PDF文档只显示前10页内容。如果日常操作的pdf文件都不超过10页&#xff0c;可以考虑使用Free Spi…...

又一挣钱副业:AI生成影视解说,半个月涨粉变现3.5W+!

这两年大家都在感叹生活不易&#xff0c;然而我想说的是&#xff0c;机会还是有的&#xff0c;但问题不在于有没有&#xff0c;而在于你是否能够认准机会&#xff0c;然后抓住它。 接触过很多咨询项目的人&#xff0c;发现很多人依旧停留在传统思维中&#xff0c;认为副业就是…...

R语言 基础 笔记 3

起因, 目的: 思考一个问题: AI 这么强,AI 什么都知道,为什么还要学习这些基础的东西, 为什么还要写这些笔记? 我觉得,大体过一遍,还是有好处的。 有个大致印象,下次查的时候,也方便一些。 几个函数 cbind() 按照列,拼接数据, 会改变某些列的数据类型。data() 查看…...

【MySQL】常见的SQL优化方式(一)

目录 1、插入数据 &#xff08;1&#xff09;批量插入 &#xff08;2&#xff09;手动提交事务 &#xff08;3&#xff09;主键顺序插入 2、主键优化 &#xff08;1&#xff09;页分裂 &#xff08;2&#xff09;页合并 3、order by 优化 &#xff08;1&#xff09;排…...

【重点】使用axios.request.put上传文件,报错分析

使用axios的put方法上传文件时&#xff0c;如果遇到错误&#xff0c;可能的原因有以下几点&#xff1a; 跨域问题&#xff1a;如果请求的URL与当前页面的域名不同&#xff0c;可能会触发跨域问题。解决方法是在服务器端设置允许跨域请求&#xff0c;如设置CORS&#xff08;跨域…...

最新最全的阿里大模型面试真题!看到就是赚到

前言 随着人工智能技术的飞速发展&#xff0c;计算机视觉&#xff08;CV&#xff09;、自然语言处理&#xff08;NLP&#xff09;、搜索、推荐、广告推送和风险控制等领域的岗位越来越受到追捧&#xff0c;掌握大型模型技术已成为这些岗位的必备技能。然而&#xff0c;目前公开…...

龙虎榜——20250610

上证指数放量收阴线&#xff0c;个股多数下跌&#xff0c;盘中受消息影响大幅波动。 深证指数放量收阴线形成顶分型&#xff0c;指数短线有调整的需求&#xff0c;大概需要一两天。 2025年6月10日龙虎榜行业方向分析 1. 金融科技 代表标的&#xff1a;御银股份、雄帝科技 驱动…...

React Native 导航系统实战(React Navigation)

导航系统实战&#xff08;React Navigation&#xff09; React Navigation 是 React Native 应用中最常用的导航库之一&#xff0c;它提供了多种导航模式&#xff0c;如堆栈导航&#xff08;Stack Navigator&#xff09;、标签导航&#xff08;Tab Navigator&#xff09;和抽屉…...

线程与协程

1. 线程与协程 1.1. “函数调用级别”的切换、上下文切换 1. 函数调用级别的切换 “函数调用级别的切换”是指&#xff1a;像函数调用/返回一样轻量地完成任务切换。 举例说明&#xff1a; 当你在程序中写一个函数调用&#xff1a; funcA() 然后 funcA 执行完后返回&…...

YSYX学习记录(八)

C语言&#xff0c;练习0&#xff1a; 先创建一个文件夹&#xff0c;我用的是物理机&#xff1a; 安装build-essential 练习1&#xff1a; 我注释掉了 #include <stdio.h> 出现下面错误 在你的文本编辑器中打开ex1文件&#xff0c;随机修改或删除一部分&#xff0c;之后…...

高危文件识别的常用算法:原理、应用与企业场景

高危文件识别的常用算法&#xff1a;原理、应用与企业场景 高危文件识别旨在检测可能导致安全威胁的文件&#xff0c;如包含恶意代码、敏感数据或欺诈内容的文档&#xff0c;在企业协同办公环境中&#xff08;如Teams、Google Workspace&#xff09;尤为重要。结合大模型技术&…...

TRS收益互换:跨境资本流动的金融创新工具与系统化解决方案

一、TRS收益互换的本质与业务逻辑 &#xff08;一&#xff09;概念解析 TRS&#xff08;Total Return Swap&#xff09;收益互换是一种金融衍生工具&#xff0c;指交易双方约定在未来一定期限内&#xff0c;基于特定资产或指数的表现进行现金流交换的协议。其核心特征包括&am…...

DBAPI如何优雅的获取单条数据

API如何优雅的获取单条数据 案例一 对于查询类API&#xff0c;查询的是单条数据&#xff0c;比如根据主键ID查询用户信息&#xff0c;sql如下&#xff1a; select id, name, age from user where id #{id}API默认返回的数据格式是多条的&#xff0c;如下&#xff1a; {&qu…...

GitHub 趋势日报 (2025年06月08日)

&#x1f4ca; 由 TrendForge 系统生成 | &#x1f310; https://trendforge.devlive.org/ &#x1f310; 本日报中的项目描述已自动翻译为中文 &#x1f4c8; 今日获星趋势图 今日获星趋势图 884 cognee 566 dify 414 HumanSystemOptimization 414 omni-tools 321 note-gen …...

Axios请求超时重发机制

Axios 超时重新请求实现方案 在 Axios 中实现超时重新请求可以通过以下几种方式&#xff1a; 1. 使用拦截器实现自动重试 import axios from axios;// 创建axios实例 const instance axios.create();// 设置超时时间 instance.defaults.timeout 5000;// 最大重试次数 cons…...

拉力测试cuda pytorch 把 4070显卡拉满

import torch import timedef stress_test_gpu(matrix_size16384, duration300):"""对GPU进行压力测试&#xff0c;通过持续的矩阵乘法来最大化GPU利用率参数:matrix_size: 矩阵维度大小&#xff0c;增大可提高计算复杂度duration: 测试持续时间&#xff08;秒&…...