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

一文全览各种 ES 查询在 Java 中的实现

2 词条查询

所谓词条查询,也就是ES不会对查询条件进行分词处理,只有当词条和查询字符串完全匹配时,才会被查询到。



2.1 等值查询-term

等值查询,即筛选出一个字段等于特定值的所有记录。



SQL:



select * from person where name = '张无忌';

而使用ES查询语句却很不一样(注意查询字段带上keyword):



GET /person/_search

{

"query": {

"term": {

"name.keyword": {

"value": "张无忌",

"boost": 1.0

}

}

}

}

ElasticSearch 5.0以后,string类型有重大变更,移除了string类型,string字段被拆分成两种新的数据类型: text用于全文搜索的,而keyword用于关键词搜索。



查询结果:



{

"took" : 0,

"timed_out" : false,

"_shards" : { // 分片信息

"total" : 1, // 总计分片数

"successful" : 1, // 查询成功的分片数

"skipped" : 0, // 跳过查询的分片数

"failed" : 0 // 查询失败的分片数

},

"hits" : { // 命中结果

"total" : {

"value" : 1, // 数量

"relation" : "eq" // 关系:等于

},

"max_score" : 2.8526313, // 最高分数

"hits" : [

{

"_index" : "person", // 索引

"_type" : "_doc", // 类型

"_id" : "1",

"_score" : 2.8526313,

"_source" : {

"address" : "光明顶",

"modifyTime" : "2021-06-29 16:48:56",

"createTime" : "2021-05-14 16:50:33",

"sect" : "明教",

"sex" : "男",

"skill" : "九阳神功",

"name" : "张无忌",

"id" : 1,

"power" : 99,

"age" : 18

}

}

]

}

}



Java 中构造 ES 请求的方式:(后续例子中只保留 SearchSourceBuilder 的构建语句)



/**

* term精确查询

*

* @throws IOException

*/

@Autowired

private RestHighLevelClient client;

@Test

public void queryTerm() throws IOException {

// 根据索引创建查询请求

SearchRequest searchRequest = new SearchRequest("person");

SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();

// 构建查询语句

searchSourceBuilder.query(QueryBuilders.termQuery("name.keyword", "张无忌"));

System.out.println("searchSourceBuilder=====================" + searchSourceBuilder);

searchRequest.source(searchSourceBuilder);

SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT);

System.out.println(JSONObject.toJSON(response));

}



仔细观察查询结果,会发现ES查询结果中会带有_score这一项,ES会根据结果匹配程度进行评分。打分是会耗费性能的,如果确认自己的查询不需要评分,就设置查询语句关闭评分:



GET /person/_search

{

"query": {

"constant_score": {

"filter": {

"term": {

"sect.keyword": {

"value": "张无忌",

"boost": 1.0

}

}

},

"boost": 1.0

}

}

}



Java构建查询语句:



SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();

// 这样构造的查询条件,将不进行score计算,从而提高查询效率

searchSourceBuilder.query(QueryBuilders.constantScoreQuery(QueryBuilders.termQuery("sect.keyword", "明教")));

2.2 多值查询-terms

多条件查询类似 Mysql 里的IN 查询,例如:



select * from persons where sect in('明教','武当派');

ES查询语句:



GET /person/_search

{

"query": {

"terms": {

"sect.keyword": [

"明教",

"武当派"

],

"boost": 1.0

}

}

}

Java 实现:



SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();

// 构建查询语句

searchSourceBuilder.query(QueryBuilders.termsQuery("sect.keyword", Arrays.asList("明教", "武当派")));

}

2.3 范围查询-range

范围查询,即查询某字段在特定区间的记录。



SQL:



select * from pesons where age between 18 and 22;

ES查询语句:



GET /person/_search

{

"query": {

"range": {

"age": {

"from": 10,

"to": 20,

"include_lower": true,

"include_upper": true,

"boost": 1.0

}

}

}

Java构建查询条件:



SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();

// 构建查询语句

searchSourceBuilder.query(QueryBuilders.rangeQuery("age").gte(10).lte(30));

}

2.4 前缀查询-prefix

前缀查询类似于SQL中的模糊查询。



SQL:



select * from persons where sect like '武当%';

ES查询语句:



{

"query": {

"prefix": {

"sect.keyword": {

"value": "武当",

"boost": 1.0

}

}

}

}

Java构建查询条件:



SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();

// 构建查询语句

searchSourceBuilder.query(QueryBuilders.prefixQuery("sect.keyword","武当"));

}

2.5 通配符查询-wildcard

通配符查询,与前缀查询类似,都属于模糊查询的范畴,但通配符显然功能更强。



SQL:



select * from persons where name like '张%忌';

ES查询语句:



{

"query": {

"wildcard": {

"sect.keyword": {

"wildcard": "张*忌",

"boost": 1.0

}

}

}

}

Java构建查询条件:



SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();

// 构建查询语句

searchSourceBuilder.query(QueryBuilders.wildcardQuery("sect.keyword","张*忌"));

03 负责查询

前面的例子都是单个条件查询,在实际应用中,我们很有可能会过滤多个值或字段。先看一个简单的例子:



select * from persons where sex = '女' and sect = '明教';

这样的多条件等值查询,就要借用到组合过滤器了,其查询语句是:



{

"query": {

"bool": {

"must": [

{

"term": {

"sex": {

"value": "女",

"boost": 1.0

}

}

},

{

"term": {

"sect.keywords": {

"value": "明教",

"boost": 1.0

}

}

}

],

"adjust_pure_negative": true,

"boost": 1.0

}

}

}



Java构造查询语句:



SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();

// 构建查询语句

searchSourceBuilder.query(QueryBuilders.boolQuery()

.must(QueryBuilders.termQuery("sex", "女"))

.must(QueryBuilders.termQuery("sect.keyword", "明教"))

);

3.1 布尔查询

布尔过滤器(bool filter)属于复合过滤器(compound filter)的一种 ,可以接受多个其他过滤器作为参数,并将这些过滤器结合成各式各样的布尔(逻辑)组合。







bool 过滤器下可以有4种子条件,可以任选其中任意一个或多个。filter是比较特殊的,这里先不说。



{

"bool" : {

"must" : [],

"should" : [],

"must_not" : [],

}

}

must:所有的语句都必须匹配,与 ‘=’ 等价。

must_not:所有的语句都不能匹配,与 ‘!=’ 或 not in 等价。

should:至少有n个语句要匹配,n由参数控制。

精度控制:



所有 must 语句必须匹配,所有 must_not 语句都必须不匹配,但有多少 should 语句应该匹配呢?默认情况下,没有 should 语句是必须匹配的,只有一个例外:那就是当没有 must 语句的时候,至少有一个 should 语句必须匹配。



我们可以通过 minimum_should_match 参数控制需要匹配的 should 语句的数量,它既可以是一个绝对的数字,又可以是个百分比:



GET /person/_search

{

"query": {

"bool": {

"must": [

{

"term": {

"sex": {

"value": "女",

"boost": 1.0

}

}

}

],

"should": [

{

"term": {

"address.keyword": {

"value": "峨眉山",

"boost": 1.0

}

}

},

{

"term": {

"sect.keyword": {

"value": "明教",

"boost": 1.0

}

}

}

],

"adjust_pure_negative": true,

"minimum_should_match": "1",

"boost": 1.0

}

}

}



Java构建查询语句:



SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();

// 构建查询语句

searchSourceBuilder.query(QueryBuilders.boolQuery()

.must(QueryBuilders.termQuery("sex", "女"))

.should(QueryBuilders.termQuery("address.word", "峨眉山"))

.should(QueryBuilders.termQuery("sect.keyword", "明教"))

.minimumShouldMatch(1)

);

最后,看一个复杂些的例子,将bool的各子句联合使用:



select * from persons where sex = '女' and age between 30 and 40 and sect != '明教' and (address = '峨眉山' OR skill = '暗器')

用 Elasticsearch 来表示上面的 SQL 例子:



GET /person/_search

{

"query": {

"bool": {

"must": [

{

"term": {

"sex": {

"value": "女",

"boost": 1.0

}

}

},

{

"range": {

"age": {

"from": 30,

"to": 40,

"include_lower": true,

"include_upper": true,

"boost": 1.0

}

}

}

],

"must_not": [

{

"term": {

"sect.keyword": {

"value": "明教",

"boost": 1.0

}

}

}

],

"should": [

{

"term": {

"address.keyword": {

"value": "峨眉山",

"boost": 1.0

}

}

},

{

"term": {

"skill.keyword": {

"value": "暗器",

"boost": 1.0

}

}

}

],

"adjust_pure_negative": true,

"minimum_should_match": "1",

"boost": 1.0

}

}

}



用Java构建这个查询条件:



SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();

// 构建查询语句

BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery()

.must(QueryBuilders.termQuery("sex", "女"))

.must(QueryBuilders.rangeQuery("age").gte(30).lte(40))

.mustNot(QueryBuilders.termQuery("sect.keyword", "明教"))

.should(QueryBuilders.termQuery("address.keyword", "峨眉山"))

.should(QueryBuilders.rangeQuery("power.keyword").gte(50).lte(80))

.minimumShouldMatch(1); // 设置should至少需要满足几个条件

// 将BoolQueryBuilder构建到SearchSourceBuilder中

searchSourceBuilder.query(boolQueryBuilder);

3.2 Filter查询

query和filter的区别:query查询的时候,会先比较查询条件,然后计算分值,最后返回文档结果;而filter是先判断是否满足查询条件,如果不满足会缓存查询结果(记录该文档不满足结果),满足的话,就直接缓存结果,filter不会对结果进行评分,能够提高查询效率。



filter的使用方式比较多样,下面用几个例子演示一下。



方式一,单独使用:



{

"query": {

"bool": {

"filter": [

{

"term": {

"sex": {

"value": "男",

"boost": 1.0

}

}

}

],

"adjust_pure_negative": true,

"boost": 1.0

}

}

}



单独使用时,filter与must基本一样,不同的是filter不计算评分,效率更高。



Java构建查询语句:



SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();

// 构建查询语句

searchSourceBuilder.query(QueryBuilders.boolQuery()

.filter(QueryBuilders.termQuery("sex", "男"))

);

方式二,和must、must_not同级,相当于子查询:



select * from (select * from persons where sect = '明教')) a where sex = '女';

ES查询语句:



{

"query": {

"bool": {

"must": [

{

"term": {

"sect.keyword": {

"value": "明教",

"boost": 1.0

}

}

}

],

"filter": [

{

"term": {

"sex": {

"value": "女",

"boost": 1.0

}

}

}

],

"adjust_pure_negative": true,

"boost": 1.0

}

}

}



Java:



SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();

// 构建查询语句

searchSourceBuilder.query(QueryBuilders.boolQuery()

.must(QueryBuilders.termQuery("sect.keyword", "明教"))

.filter(QueryBuilders.termQuery("sex", "女"))

);

方式三,将must、must_not置于filter下,这种方式是最常用的:



{

"query": {

"bool": {

"filter": [

{

"bool": {

"must": [

{

"term": {

"sect.keyword": {

"value": "明教",

"boost": 1.0

}

}

},

{

"range": {

"age": {

"from": 20,

"to": 35,

"include_lower": true,

"include_upper": true,

"boost": 1.0

}

}

}

],

"must_not": [

{

"term": {

"sex.keyword": {

"value": "女",

"boost": 1.0

}

}

}

],

"adjust_pure_negative": true,

"boost": 1.0

}

}

],

"adjust_pure_negative": true,

"boost": 1.0

}

}

}



Java:



SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();

// 构建查询语句

searchSourceBuilder.query(QueryBuilders.boolQuery()

.filter(QueryBuilders.boolQuery()

.must(QueryBuilders.termQuery("sect.keyword", "明教"))

.must(QueryBuilders.rangeQuery("age").gte(20).lte(35))

.mustNot(QueryBuilders.termQuery("sex.keyword", "女")))

);

04 聚合查询

接下来,我们将用一些案例演示ES聚合查询。



4.1 最值、平均值、求和

案例:查询最大年龄、最小年龄、平均年龄。



SQL:



select max(age) from persons;

ES:



GET /person/_search

{

"aggregations": {

"max_age": {

"max": {

"field": "age"

}

}

}

}

Java:



@Autowired

private RestHighLevelClient client;

@Test

public void maxQueryTest() throws IOException {

// 聚合查询条件

AggregationBuilder aggBuilder = AggregationBuilders.max("max_age").field("age");

SearchRequest searchRequest = new SearchRequest("person");

SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();

// 将聚合查询条件构建到SearchSourceBuilder中

searchSourceBuilder.aggregation(aggBuilder);

System.out.println("searchSourceBuilder----->" + searchSourceBuilder);

searchRequest.source(searchSourceBuilder);

// 执行查询,获取SearchResponse

SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT);

System.out.println(JSONObject.toJSON(response));

}



使用聚合查询,结果中默认只会返回10条文档数据(当然我们关心的是聚合的结果,而非文档)。返回多少条数据可以自主控制:



GET /person/_search

{

"size": 20,

"aggregations": {

"max_age": {

"max": {

"field": "age"

}

}

}

}

而Java中只需增加下面一条语句即可:



searchSourceBuilder.size(20);

与max类似,其他统计查询也很简单:



AggregationBuilder minBuilder = AggregationBuilders.min("min_age").field("age");

AggregationBuilder avgBuilder = AggregationBuilders.avg("min_age").field("age");

AggregationBuilder sumBuilder = AggregationBuilders.sum("min_age").field("age");

AggregationBuilder countBuilder = AggregationBuilders.count("min_age").field("age");

4.2 去重查询

案例:查询一共有多少个门派。



SQL:



select count(distinct sect) from persons;

ES:



{

"aggregations": {

"sect_count": {

"cardinality": {

"field": "sect.keyword"

}

}

}

}

Java:



@Test

public void cardinalityQueryTest() throws IOException {

// 创建某个索引的request

SearchRequest searchRequest = new SearchRequest("person");

// 查询条件

SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();

// 聚合查询

AggregationBuilder aggBuilder = AggregationBuilders.cardinality("sect_count").field("sect.keyword");

searchSourceBuilder.size(0);

// 将聚合查询构建到查询条件中

searchSourceBuilder.aggregation(aggBuilder);

System.out.println("searchSourceBuilder----->" + searchSourceBuilder);

searchRequest.source(searchSourceBuilder);

// 执行查询,获取结果

SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT);

System.out.println(JSONObject.toJSON(response));

}



4.3 分组聚合

4.3.1 单条件分组

案例:查询每个门派的人数



SQL:



select sect,count(id) from mytest.persons group by sect;

ES:



{

"size": 0,

"aggregations": {

"sect_count": {

"terms": {

"field": "sect.keyword",

"size": 10,

"min_doc_count": 1,

"shard_min_doc_count": 0,

"show_term_doc_count_error": false,

"order": [

{

"_count": "desc"

},

{

"_key": "asc"

}

]

}

}

}

}



Java:



SearchRequest searchRequest = new SearchRequest("person");

SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();

searchSourceBuilder.size(0);

// 按sect分组

AggregationBuilder aggBuilder = AggregationBuilders.terms("sect_count").field("sect.keyword");

searchSourceBuilder.aggregation(aggBuilder);

4.3.2 多条件分组

案例:查询每个门派各有多少个男性和女性



SQL:



select sect,sex,count(id) from mytest.persons group by sect,sex;

ES:



{

"aggregations": {

"sect_count": {

"terms": {

"field": "sect.keyword",

"size": 10

},

"aggregations": {

"sex_count": {

"terms": {

"field": "sex.keyword",

"size": 10

}

}

}

}

}

}



4.4 过滤聚合

前面所有聚合的例子请求都省略了 query ,整个请求只不过是一个聚合。这意味着我们对全部数据进行了聚合,但现实应用中,我们常常对特定范围的数据进行聚合,例如下例。



案例:查询明教中的最大年龄。这涉及到聚合与条件查询一起使用。



SQL:



select max(age) from mytest.persons where sect = '明教';

ES:



GET /person/_search

{

"query": {

"term": {

"sect.keyword": {

"value": "明教",

"boost": 1.0

}

}

},

"aggregations": {

"max_age": {

"max": {

"field": "age"

}

}

}

}



Java:



SearchRequest searchRequest = new SearchRequest("person");

SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();

// 聚合查询条件

AggregationBuilder maxBuilder = AggregationBuilders.max("max_age").field("age");

// 等值查询

searchSourceBuilder.query(QueryBuilders.termQuery("sect.keyword", "明教"));

searchSourceBuilder.aggregation(maxBuilder);

另外还有一些更复杂的查询例子。



案例:查询0-20,21-40,41-60,61以上的各有多少人。



SQL:



select

sum(case when age<=20 then 1 else 0 end) ageGroup1,

sum(case when age >20 and age <=40 then 1 else 0 end) ageGroup2,

sum(case when age >40 and age <=60 then 1 else 0 end) ageGroup3,

sum(case when age >60 and age <=200 then 1 else 0 end) ageGroup4

from

mytest.persons;

ES:



{

"size": 0,

"aggregations": {

"age_avg": {

"range": {

"field": "age",

"ranges": [

{

"from": 0.0,

"to": 20.0

},

{

"from": 21.0,

"to": 40.0

},

{

"from": 41.0,

"to": 60.0

},

{

"from": 61.0,

"to": 200.0

}

],

"keyed": false

}

}

}

}



查询结果:



"aggregations" : {

"age_avg" : {

"buckets" : [

{

"key" : "0.0-20.0",

"from" : 0.0,

"to" : 20.0,

"doc_count" : 3

},

{

"key" : "21.0-40.0",

"from" : 21.0,

"to" : 40.0,

"doc_count" : 13

},

{

"key" : "41.0-60.0",

"from" : 41.0,

"to" : 60.0,

"doc_count" : 4

},

{

"key" : "61.0-200.0",

"from" : 61.0,

"to" : 200.0,

"doc_count" : 1

}

]

}

}





原文链接:https://blog.csdn.net/wang20010104/article/details/130482294

相关文章:

一文全览各种 ES 查询在 Java 中的实现

2 词条查询 所谓词条查询&#xff0c;也就是ES不会对查询条件进行分词处理&#xff0c;只有当词条和查询字符串完全匹配时&#xff0c;才会被查询到。 &#xfeff; 2.1 等值查询-term 等值查询&#xff0c;即筛选出一个字段等于特定值的所有记录。 &#xfeff; SQL&…...

Centralized Feature Pyramid for Object Detection解读

Centralized Feature Pyramid for Object Detection 问题 主流的特征金字塔集中于层间特征交互&#xff0c;而忽略了层内特征规则。尽管一些方法试图在注意力机制或视觉变换器的帮助下学习紧凑的层内特征表示&#xff0c;但它们忽略了对密集预测任务非常重要的被忽略的角点区…...

unity中meta文件GUID异常问题

错误信息&#xff1a; The .meta file Assets/Scripts/Editor/ConvertConfigToBinary/TxtConverter.cs.meta does not have a valid GUID and its corresponding Asset file will be ignored. If this file is not malformed, please add a GUID, or delete the .meta file and…...

【k8s】pod集群调度

调度约束 Kubernetes 是通过 List-Watch **** 的机制进行每个组件的协作&#xff0c;保持数据同步的&#xff0c;每个组件之间的设计实现了解耦。 用户是通过 kubectl 根据配置文件&#xff0c;向 APIServer 发送命令&#xff0c;在 Node 节点上面建立 Pod 和 Container。…...

MathType数学公式编辑器2024官方最新版

Mathtype是一款数学公式编辑器&#xff0c;它可以帮助我们在文档中插入各种复杂的数学公式&#xff0c;使得我们的文档更加专业、规范。在使用Mathtype工具时&#xff0c;我们可以采取以下几种方法&#xff1a; 1. 鼠标直接点击插入公式 打开Mathtype后&#xff0c;在需要插入公…...

Android照搬,可删

1private void initview() {myradioGroup (RadioGroup) this.findViewById(R.id.MainActivity_RadioGroup);//通过id找到UI中的单选按钮组 2res getResources();// 得到Resources对象&#xff0c;从而通过它获取存在系统的资源 icon_home_true res.getDrawable(R.mipmap.ic…...

2022最新版-李宏毅机器学习深度学习课程-P26 自注意力机制

一、应用情境 输入任意长度个向量进行处理。 从输入看 文字处理&#xff08;自然语言处理&#xff09; 将word表示为向量 one-hotword-embedding声音信号处理 每个时间窗口&#xff08;Window, 25ms&#xff09;视为帧&#xff08;Frame&#xff09;,视为向量图 每个节点视为…...

【Docker】Linux路由连接两个不同网段namespace,连接namespace与主机

如果两个namespace处于不同的子网中&#xff0c;那么就不能通过bridge进行连接了&#xff0c;而是需要通过路由器进行三层转发。然而Linux并未像提供虚拟网桥一样也提供一个虚拟路由器设备&#xff0c;原因是Linux自身就具备有路由器功能。 路由器的工作原理是这样的&#xff…...

C语言 DAY10 内存分配

1.引入 int nums[10] {0}; //对 int len 10; int nums[len] {0}; //错 是因为系统的内存分配原则导致的 2.概述 在系统运行时&#xff0c;系统为了更好的管理进程中的内存&#xff0c;所以将内存进行了分配,其分配的机制就称为内存分配 1.静态分配原则 1.特点 1、在程序…...

SpringCloud Gateway 网关的请求体body的读取和修改

SpringCloud Gateway 网关的请求体body的读取和修改 getway需要多次对body 进行操作&#xff0c;需要对body 进行缓存 缓存body 动态多次获取 新建顶层filter&#xff0c;对body 进行缓存 import lombok.extern.slf4j.Slf4j; import org.springframework.cloud.gateway.filt…...

气膜场馆的降噪方法

在现代社会&#xff0c;噪音已经成为我们生活中难以避免的问题&#xff0c;而气膜场馆也不例外。传统的气膜场馆常常因其特殊结构而面临噪音扩散和回声问题&#xff0c;影响了人们的体验和活动效果。然而&#xff0c;随着科技的进步&#xff0c;多功能声学综合馆应运而生&#…...

探索主题建模:使用LDA分析文本主题

在数据分析和文本挖掘领域&#xff0c;主题建模是一种强大的工具&#xff0c;用于自动发现文本数据中的隐藏主题。Latent Dirichlet Allocation&#xff08;LDA&#xff09;是主题建模的一种常用技术。本文将介绍如何使用Python和Gensim库执行LDA主题建模&#xff0c;并探讨主题…...

服务器黑洞,如何秒解

想必这样的短信大家都应该见过吧&#xff0c;这其实是阿里云服务器被攻击后触发的黑洞机制的短信通知。还有很多朋友不知道&#xff0c;为什么要这么做。原因其实很简单啊&#xff0c;当同一个机房的ip段&#xff0c;如果说有一台服务器遭受低道攻击&#xff0c;那么很可能会造…...

【生物信息学】单细胞RNA测序数据分析:计算亲和力矩阵(基于距离、皮尔逊相关系数)及绘制热图(Heatmap)

文章目录 一、实验介绍二、实验环境1. 配置虚拟环境2. 库版本介绍 三、实验内容0. 导入必要的库1. 读取数据集2. 质量控制&#xff08;可选&#xff09;3. 基于距离的亲和力矩阵4. 绘制基因表达的Heatmap5. 基于皮尔逊相关系数的亲和力矩阵6. 代码整合 一、实验介绍 计算亲和力…...

学习笔记三十一:k8s安全管理:认证、授权、准入控制概述SA介绍

K8S安全实战篇之RBAC认证授权-v1 k8s安全管理&#xff1a;认证、授权、准入控制概述认证k8s客户端访问apiserver的几种认证方式客户端认证&#xff1a;BearertokenServiceaccountkubeconfig文件 授权Kubernetes的授权是基于插件形成的&#xff0c;其常用的授权插件有以下几种&a…...

【开发新的】apache common BeanUtils忽略null值

前言: BeanUtils默认的populate方法不会忽略空值和null值&#xff0c;在特定场景&#xff0c;我们需要原始的值避免被覆盖&#xff0c;所以这里提供一种自定义实现方式。 package com.hmwl.service.program;import lombok.extern.slf4j.Slf4j; import org.apache.commons.beanu…...

coalesce函数(SQL )

用途&#xff1a; 将控制替换成其他值&#xff1b;返回第一个非空值 表达式 COALESCE是一个函数&#xff0c; (expression_1, expression_2, …,expression_n)依次参考各参数表达式&#xff0c;遇到非null值即停止并返回该值。如果所有的表达式都是空值&#xff0c;最终将返…...

一键报警可视对讲管理机10寸触摸屏管理机

一键报警可视对讲管理机10寸触摸屏管理机 一、管理机技术指标&#xff1a; 1、10寸LCD触摸屏&#xff0c;分辨率1024*600&#xff1b; 2、摄像头1200万像素 3、1000M/100M自适应网口&#xff1b; 4、按键设置&#xff1a;报警/呼叫按键&#xff0c;通话/挂机按键&#xff0…...

java左右括号

java左右括号 数据结构-栈栈的特点&#xff1a;先进后出代码实现 最近看到有小伙伴去面试&#xff0c;被人问起一道算法题&#xff0c;题目内容大概是&#xff1a;给定一个字符串&#xff0c;如&#xff1a;“[[]]{}”&#xff0c;判断字符串是否为有效的括号。考查的是数据结构…...

接口自动化测试 —— 工具、请求与响应

一、工具&#xff1a; 1.工具介绍 postman &#xff1a;很主流的API测试工具&#xff0c;也是工作里面使用最广泛的研发工具。 JMeter&#xff1a; ApiPost&#xff1a; 2.安装postman&#xff1a; 安装好直接打开&#xff0c;不用注册。 二、通信模式&#xff1a; 1、…...

Java如何权衡是使用无序的数组还是有序的数组

在 Java 中,选择有序数组还是无序数组取决于具体场景的性能需求与操作特点。以下是关键权衡因素及决策指南: ⚖️ 核心权衡维度 维度有序数组无序数组查询性能二分查找 O(log n) ✅线性扫描 O(n) ❌插入/删除需移位维护顺序 O(n) ❌直接操作尾部 O(1) ✅内存开销与无序数组相…...

安宝特方案丨XRSOP人员作业标准化管理平台:AR智慧点检验收套件

在选煤厂、化工厂、钢铁厂等过程生产型企业&#xff0c;其生产设备的运行效率和非计划停机对工业制造效益有较大影响。 随着企业自动化和智能化建设的推进&#xff0c;需提前预防假检、错检、漏检&#xff0c;推动智慧生产运维系统数据的流动和现场赋能应用。同时&#xff0c;…...

Swift 协议扩展精进之路:解决 CoreData 托管实体子类的类型不匹配问题(下)

概述 在 Swift 开发语言中&#xff0c;各位秃头小码农们可以充分利用语法本身所带来的便利去劈荆斩棘。我们还可以恣意利用泛型、协议关联类型和协议扩展来进一步简化和优化我们复杂的代码需求。 不过&#xff0c;在涉及到多个子类派生于基类进行多态模拟的场景下&#xff0c;…...

《通信之道——从微积分到 5G》读书总结

第1章 绪 论 1.1 这是一本什么样的书 通信技术&#xff0c;说到底就是数学。 那些最基础、最本质的部分。 1.2 什么是通信 通信 发送方 接收方 承载信息的信号 解调出其中承载的信息 信息在发送方那里被加工成信号&#xff08;调制&#xff09; 把信息从信号中抽取出来&am…...

网络编程(UDP编程)

思维导图 UDP基础编程&#xff08;单播&#xff09; 1.流程图 服务器&#xff1a;短信的接收方 创建套接字 (socket)-----------------------------------------》有手机指定网络信息-----------------------------------------------》有号码绑定套接字 (bind)--------------…...

是否存在路径(FIFOBB算法)

题目描述 一个具有 n 个顶点e条边的无向图&#xff0c;该图顶点的编号依次为0到n-1且不存在顶点与自身相连的边。请使用FIFOBB算法编写程序&#xff0c;确定是否存在从顶点 source到顶点 destination的路径。 输入 第一行两个整数&#xff0c;分别表示n 和 e 的值&#xff08;1…...

学校时钟系统,标准考场时钟系统,AI亮相2025高考,赛思时钟系统为教育公平筑起“精准防线”

2025年#高考 将在近日拉开帷幕&#xff0c;#AI 监考一度冲上热搜。当AI深度融入高考&#xff0c;#时间同步 不再是辅助功能&#xff0c;而是决定AI监考系统成败的“生命线”。 AI亮相2025高考&#xff0c;40种异常行为0.5秒精准识别 2025年高考即将拉开帷幕&#xff0c;江西、…...

Java数值运算常见陷阱与规避方法

整数除法中的舍入问题 问题现象 当开发者预期进行浮点除法却误用整数除法时,会出现小数部分被截断的情况。典型错误模式如下: void process(int value) {double half = value / 2; // 整数除法导致截断// 使用half变量 }此时...

Caliper 配置文件解析:fisco-bcos.json

config.yaml 文件 config.yaml 是 Caliper 的主配置文件,通常包含以下内容: test:name: fisco-bcos-test # 测试名称description: Performance test of FISCO-BCOS # 测试描述workers:type: local # 工作进程类型number: 5 # 工作进程数量monitor:type: - docker- pro…...

VisualXML全新升级 | 新增数据库编辑功能

VisualXML是一个功能强大的网络总线设计工具&#xff0c;专注于简化汽车电子系统中复杂的网络数据设计操作。它支持多种主流总线网络格式的数据编辑&#xff08;如DBC、LDF、ARXML、HEX等&#xff09;&#xff0c;并能够基于Excel表格的方式生成和转换多种数据库文件。由此&…...