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

ES 7.6 - JAVA应用基础操作篇

ES 7.6 - JAVA应用基础操作篇

    • 环境准备
      • 依赖配置
    • 实体类准备
    • 使用说明
    • 索引/映射操作
      • 创建索引和映射
      • 索引和映射相关查询
      • 删除索引
    • 文档操作
      • 插入数据
      • 更新数据
      • 删除数据
      • 批量操作
    • 文档查询
      • 根据ID查询
      • 根据字段精准查询
      • 根据字段分词查询
      • 控制返回字段
      • 范围查询
      • 组合查询
      • 排序+分页
      • 高亮搜索
      • 聚合查询
    • 场景查询实操
      • 查询2023年中男、女的数量并找出对应的最大/最小年龄
      • 查询在地址中包含 "深圳" 或者 备注中包含 "积极" 的 男性青年(18-30岁)
      • 要求根据关键字找出匹配项目标,高亮实时预览
      • 分别找出男、女性别中年龄最小的三个人(TOP N)
      • 查询tag中带有某些标签的或者出身地在某某地的人,按照年龄降序,并且分页
    • 总结

上文已经教了大家最基本的操作了,那我们在java代码里面要如何实现呢?本文的目的就是教大家在springboot框架下实现上文的API操作,也就是CURD!

环境准备

首先我们要知道ES的API都是HTTP请求!!!!,所以什么语言都可以操作,就是发送请求和处理返回而已嘛,只是说现在这种封装不需要我们做,有人做好了,这种叫做ES的客户端!

依赖配置

我们直接采用Spring-data-es的依赖,先看一下版本依赖说明:

在这里插入图片描述

这里建议客户端版本和你自身搭建的es版本保持一致(es不同版本间api差异很大,如果不想出现莫名其妙的错的最好一致),所以这里我们选择springboot 2.3版本,这里给出spring-data-es的官方文档

# springboot版本
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.3.2.RELEASE</version><relativePath/> <!-- lookup parent from repository -->
</parent># spring-elasticsearch依赖
<dependency><groupId>org.springframework.data</groupId><artifactId>spring-data-elasticsearch</artifactId><version>4.0.9.RELEASE</version>
</dependency>

因为我这ES是7.6的,所以选择使用HighLevelRestClient客户端,虽然这个已经在高版本过时了(8.x),但是在7.x版本里面官方建议使用这个

在这里插入图片描述

项目引入依赖后,使用非常简单,文件中配置一下ES地址,就可以愉快的访问啦:

# yml配置文件
spring:elasticsearch:rest:uris: ip:portusername: password: 

实体类准备

@Data
@Document(indexName = "es_apply_test")
public class EsTest {@Idprivate Long id;@Field(type = FieldType.Text,analyzer = "ik_max_word")private String name;@Field(type = FieldType.Keyword)private String sex;@Field(type = FieldType.Integer)private Integer age;@Field(type = FieldType.Text,analyzer = "ik_max_word")private String remark;@Field(type = FieldType.Keyword)private String[] tag;@Field(type = FieldType.Text,analyzer = "ik_max_word")private String addressLocation;@Field(type = FieldType.Keyword)private String birthAddress;@Field(type = FieldType.Date,pattern = "yyyy-MM-dd HH:mm:ss",format = DateFormat.custom)private Date createTime;@Field(type = FieldType.Boolean)private Boolean hasGirlFriend;public EsTest(){}// 下面都是为了生成测试数据而准备的private final static String[] city=new String[]{"深圳","广州","上海","北京","武汉"};private final static String[] address=new String[]{"北京市朝阳区北辰东路15号","上海市黄浦区人民大道200号","深圳市福田区福中三路市民中心C区","武汉市江岸区一元街道沿江大道188号","广州市花都区新华街新都大道68号"};public static EsTest getRandomData(Long id){EsTest esTest = new EsTest();esTest.setId(id);esTest.setName(RandomUtil.randomString("张三李四王五陈六江文档词测试",3));esTest.setSex(id%2==0 ? "男":"女");esTest.setAge(RandomUtil.randomInt(15,30));esTest.setRemark(RandomUtil.randomString("活波开朗,具有进取精神和团队精神,有较强的动手能力。良好协调沟通能力,适应力强,反应快、积极、细心、灵活, 具有一定的社会交往能力",15));esTest.setTag(new String[]{RandomUtil.randomString("活波开朗,具有进取精神和团队精神,有较强的动手能力。良好协调沟通能力,适应力强,反应快、积极、细心、灵活, 具有一定的社会交往能力",3),RandomUtil.randomString("活波开朗,具有进取精神和团队精神,有较强的动手能力。良好协调沟通能力,适应力强,反应快、积极、细心、灵活, 具有一定的社会交往能力",3),RandomUtil.randomString("活波开朗,具有进取精神和团队精神,有较强的动手能力。良好协调沟通能力,适应力强,反应快、积极、细心、灵活, 具有一定的社会交往能力",3)});esTest.setAddressLocation(address[RandomUtil.randomInt(0,address.length-1)]);esTest.setBirthAddress(city[RandomUtil.randomInt(0,city.length-1)]);esTest.setCreateTime(RandomUtil.randomDay(0,100));esTest.setHasGirlFriend(id%4==0 ? true:false);return esTest;}}
  • 注解:@Document用来声明Java对象与ElasticSearch索引的关系

    indexName 索引名称

    type 索引类型

    shards 主分区数量

    replicas 副本分区数量

    createIndex 索引不存在时,是否自动创建索引,默认true

    不建议自动创建索引(自动创建的索引 是按着默认类型和默认分词器)

  • 注解:@Id 表示索引的主键

  • 注解:@Field 用来描述字段的ES数据类型,是否分词等配置,等于Mapping描述

    index 设置字段是否索引,默认是true,如果是false则该字段不能被查询

    store 默认为no,被store标记的fields被存储在和index不同的fragment中,以便于快速检索。虽然store占用磁盘空间,但是减少了计算。

    type 数据类型(text、keyword、date、object、geo等)

    analyzer 对字段使用分词器,注意一般如果要使用分词器,字段的type一般是text。

    format 定义日期时间格式,详细见 官方文档: https://www.elastic.co/guide/reference/mapping/date-format/.

  • 注解:@CompletionField 定义关键词索引 要完成补全搜索

    analyzer 对字段使用分词器,注意一般如果要使用分词器,字段的type一般是text。

    searchAnalyzer 显示指定搜索时分词器,默认是和索引是同一个,保证分词的一致性。

    maxInputLength:设置单个输入的长度,默认为50 UTF-16 代码点

使用说明

我们引入依赖后,在使用的时候有四种使用方式(下面我由简→难说明一下):

  • ElasticsearchRepository:自动生成简单CURD方法,直接调用即可(复杂的不友好)
  • ElasticsearchRestTemplate:内部使用的是RestHighLevelClient,它帮我们封装了一层
  • RestHighLevelClient:直接使用客户端
  • 自己封装客户端:之前说了本质就是HTTP请求,自己封装一下,直接调API呗,这比啥都好使

本文使用ElasticsearchRestTemplate(对小白友好),但是我个人强烈推荐直接用RestHighLevelClient,因为这个支持得更全面还同时支持同步和异步操作,本文有些操作也会用到这个

本文索引名称:es_apply_test

客户端注入:

在这里插入图片描述

索引/映射操作

创建索引和映射

@Test
void createIndexAndMapping() {IndexOperations indexOperations = elasticsearchRestTemplate.indexOps(EsTest.class);// 判断索引是否已经存在if(!indexOperations.exists()){// 不存在则创建indexOperations.create();Document mapping = indexOperations.createMapping(EsTest.class);indexOperations.putMapping(mapping);}log.info("使用API查询查看..................");
}

索引和映射相关查询

@Test
void queryIndexAndMapping() {IndexOperations indexOperations = elasticsearchRestTemplate.indexOps(EsTest.class);boolean exists = indexOperations.exists();log.info("索引是否存在:{}",exists);Map<String, Object> mapping = indexOperations.getMapping();log.info("映射:{}",JSONObject.toJSONString(mapping));Map<String, Object> settings = indexOperations.getSettings();log.info("索引设置:{}",JSONObject.toJSONString(settings));// 索引刷新(这个功能用处,后面讲理论的时候你会知道是干嘛的)indexOperations.refresh();
}

删除索引

@Test
void deletedIndex() {IndexOperations indexOperations = elasticsearchRestTemplate.indexOps(EsTest.class);indexOperations.delete();
}

文档操作

插入数据

/** 插入一条数据 */@Testvoid insertDoc() {// 插入一条elasticsearchRestTemplate.save(EsTest.getRandomData(1L));// 同时插入多条 实际是遍历一条一条插入而不是用的bulk命令elasticsearchRestTemplate.save(EsTest.getRandomData(2L),EsTest.getRandomData(3L));}

更新数据

    /** 更新数据 */@Testvoid updateDoc() throws IOException {// es的数据结构都是文档,其实不存在文档更新,每次更新都会产生新的文档(这个是很低效的),所以es在API方面也看的出来对更新不是很友好// 没办法,虽然更新很低效,但终究得改呀// 下面提供几种方式// 1.根据ID更新UpdateQuery build = UpdateQuery.builder("1").withDocument(Document.parse("{ \"name\": \"根据ID更新\" }")).build();elasticsearchRestTemplate.update(build,elasticsearchRestTemplate.getIndexCoordinatesFor(EsTest.class));// 2.条件更新// 采用highLevel客户端,根据查询条件 使用脚本更新 等同于_update_by_query APIUpdateByQueryRequest request = new UpdateByQueryRequest("es_apply_test");request.setQuery(QueryBuilders.termQuery("age","24"));request.setScript(new Script("ctx._source['age']='300';ctx._source['remark']='根据条件批量更新';"));restHighLevelClient.updateByQuery(request, RequestOptions.DEFAULT);}

删除数据

    /** 删除数据 */@Testvoid deleteDoc() throws IOException {// 1.根据ID删除elasticsearchRestTemplate.delete("1",EsTest.class);// 2.条件删除NativeSearchQuery build = new NativeSearchQueryBuilder().withQuery(QueryBuilders.termQuery("id", "3")).build();elasticsearchRestTemplate.delete(build,EsTest.class,elasticsearchRestTemplate.getIndexCoordinatesFor(EsTest.class));}

批量操作

    /** 批量增、删、改操作 */@Testvoid bulkDoc() throws IOException {// 量大的话强烈推荐这种方式,因为ES本身是以查询突出,修改的吞吐量并不高// 1. 批量插入BulkRequest insertRequest = new BulkRequest();for(int i=1;i<=20;i++){IndexRequest indexRequest = new IndexRequest("es_apply_test");indexRequest.id(String.valueOf(i));indexRequest.source(JSONObject.toJSONString(EsTest.getRandomData((long)i)),XContentType.JSON);insertRequest.add(indexRequest);}BulkResponse insertResult = restHighLevelClient.bulk(insertRequest, RequestOptions.DEFAULT);log.info("是否失败: {},失败原因:{}",insertResult.hasFailures(),insertResult.buildFailureMessage());// 2. 批量更新BulkRequest updateRequest = new BulkRequest();for(int i=1;i<=5;i++){UpdateRequest indexRequest = new UpdateRequest();indexRequest.id(String.valueOf(i));indexRequest.index("es_apply_test");HashMap<String, Object> objectObjectHashMap = new HashMap<>();objectObjectHashMap.put("name","bulk批量更新");indexRequest.doc(objectObjectHashMap);updateRequest.add(indexRequest);}BulkResponse updateResult = restHighLevelClient.bulk(updateRequest, RequestOptions.DEFAULT);log.info("是否失败: {},失败原因:{}",updateResult.hasFailures(),updateResult.buildFailureMessage());// 3. 批量删除BulkRequest deleteRequest = new BulkRequest();for(int i=1;i<=5;i++){DeleteRequest request = new DeleteRequest();request.id(String.valueOf(i));request.index("es_apply_test");updateRequest.add(request);}BulkResponse deleteResult = restHighLevelClient.bulk(deleteRequest, RequestOptions.DEFAULT);log.info("是否失败: {},失败原因:{}",deleteResult.hasFailures(),deleteResult.buildFailureMessage());// 当然也可混合操作 就是 _bulk API}

文档查询

根据ID查询

    /** 根据id查 */@Testvoid getDataById() {EsTest esTest = elasticsearchRestTemplate.get("1", EsTest.class);log.info("结果:{}", JSONObject.toJSONString(esTest));}

根据字段精准查询

    @Testvoid termQuery() {// term 精准查询TermQueryBuilder termQuery = QueryBuilders.termQuery("age", 10);NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(termQuery);SearchHits<EsTest> termResult = elasticsearchRestTemplate.search(nativeSearchQuery, EsTest.class);log.info("term-> 总数量:{} 结果:{}", termResult.getTotalHits(),JSONObject.toJSONString(termResult.getSearchHits()));// terms 精准查询TermsQueryBuilder termsQueryBuilder = QueryBuilders.termsQuery("tag", "良心力", "高于动");NativeSearchQuery nativeSearchQuery1 = new NativeSearchQuery(termsQueryBuilder);SearchHits<EsTest> termsResult = elasticsearchRestTemplate.search(nativeSearchQuery1, EsTest.class);log.info("terms-> 总数量:{} 结果:{}", termsResult.getTotalHits(),JSONObject.toJSONString(termsResult.getSearchHits()));}

根据字段分词查询

    /** 根据字段分词查询 */@Testvoid matchQuery() {// matchall 全量查询 默认是分页查询10条MatchAllQueryBuilder matchAllQueryBuilder = QueryBuilders.matchAllQuery();NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(matchAllQueryBuilder);SearchHits<EsTest> matchAll = elasticsearchRestTemplate.search(nativeSearchQuery, EsTest.class);log.info("match all-> 总数量:{} 结果:{}", matchAll.getTotalHits(),JSONObject.toJSONString(matchAll.getSearchHits()));// match 根据字段分词查询(字段分词)MatchQueryBuilder matchQueryBuilder = QueryBuilders.matchQuery("addressLocation", "街道");NativeSearchQuery nativeSearchQuery1 = new NativeSearchQuery(matchQueryBuilder);SearchHits<EsTest> match = elasticsearchRestTemplate.search(nativeSearchQuery1, EsTest.class);log.info("match -> 总数量:{} 结果:{}", match.getTotalHits(),JSONObject.toJSONString(match.getSearchHits()));// match_phrase 根据字段分词查询(字段不分词)MatchPhraseQueryBuilder matchPhraseQueryBuilder = QueryBuilders.matchPhraseQuery("addressLocation", "街道,武汉");NativeSearchQuery nativeSearchQuery2 = new NativeSearchQuery(matchPhraseQueryBuilder);SearchHits<EsTest> matchPhrase = elasticsearchRestTemplate.search(nativeSearchQuery2, EsTest.class);log.info("match_phrase -> 总数量:{} 结果:{}", matchPhrase.getTotalHits(),JSONObject.toJSONString(matchPhrase.getSearchHits()));// multi_match 根据字段分词查询多个字段MultiMatchQueryBuilder multiMatchQueryBuilder = QueryBuilders.multiMatchQuery("街道,武汉,队协", "addressLocation", "remark");NativeSearchQuery nativeSearchQuery3 = new NativeSearchQuery(multiMatchQueryBuilder);SearchHits<EsTest> multiMatch = elasticsearchRestTemplate.search(nativeSearchQuery3, EsTest.class);log.info("multiMatch -> 总数量:{} 结果:{}", multiMatch.getTotalHits(),JSONObject.toJSONString(multiMatch.getSearchHits()));}

控制返回字段

    /** 控制返回字段 */@Testvoid fieldFilterQuery() {// matchall 全量查询 并控制返回字段NativeSearchQuery build = new NativeSearchQueryBuilder().withQuery(QueryBuilders.matchAllQuery()).withFields("id", "name").build();SearchHits<EsTest> matchAll = elasticsearchRestTemplate.search(build, EsTest.class);log.info("match all-> 总数量:{} 结果:{}", matchAll.getTotalHits(),JSONObject.toJSONString(matchAll.getSearchHits()));}

范围查询

    /** 范围查询 */@Testvoid rangeQuery() {// 范围查询 并控制返回字段NativeSearchQuery build = new NativeSearchQueryBuilder().withQuery(QueryBuilders.rangeQuery("age").gte(20).lte(30)).withFields("id", "name","age").build();SearchHits<EsTest> matchAll = elasticsearchRestTemplate.search(build, EsTest.class);log.info("match all-> 总数量:{} 结果:{}", matchAll.getTotalHits(),JSONObject.toJSONString(matchAll.getSearchHits()));}

组合查询

    /** 组合查询 and 、or 、!= */@Testvoid boolGroupQuery() {// 范围查询 并控制返回字段// =10岁 !=男NativeSearchQuery build = new NativeSearchQueryBuilder().withQuery(QueryBuilders.boolQuery().must(QueryBuilders.termQuery("age",23)).mustNot(QueryBuilders.termQuery("sex","男"))).withFields("id", "name","age","sex").build();SearchHits<EsTest> matchAll = elasticsearchRestTemplate.search(build, EsTest.class);log.info("match all-> 总数量:{} 结果:{}", matchAll.getTotalHits(),JSONObject.toJSONString(matchAll.getSearchHits()));}

排序+分页

    /** 排序+分页 */@Testvoid sortAndPageQuery() {// 排序+分页  排序可以多个NativeSearchQuery build = new NativeSearchQueryBuilder().withQuery(QueryBuilders.matchAllQuery()).withSort(SortBuilders.fieldSort("age").order(SortOrder.ASC)).withSort(SortBuilders.fieldSort("id").order(SortOrder.DESC)).withSort(SortBuilders.scoreSort()).withFields("id", "name","age","sex").withPageable(PageRequest.of(0,5)).build();SearchHits<EsTest> matchAll = elasticsearchRestTemplate.search(build, EsTest.class);log.info("match all-> 总数量:{} 结果:{}", matchAll.getTotalHits(),JSONObject.toJSONString(matchAll.getSearchHits()));}

高亮搜索

    /** 高亮搜索 */@Testvoid highlightQuery() {// 高亮搜索NativeSearchQuery build = new NativeSearchQueryBuilder().withQuery(QueryBuilders.multiMatchQuery("武汉深圳", "addressLocation", "remark")).withFields("id", "name","addressLocation","remark").withHighlightBuilder(new HighlightBuilder().preTags("<span style='color:red'>").postTags("</span>")).withHighlightFields(new HighlightBuilder.Field("addressLocation"),new HighlightBuilder.Field("remark")).build();SearchHits<EsTest> matchAll = elasticsearchRestTemplate.search(build, EsTest.class);log.info("match all-> 总数量:{} 结果:{}", matchAll.getTotalHits(),JSONObject.toJSONString(matchAll.getSearchHits()));}

聚合查询

    /** 聚合查询 */@Testvoid aggregateQuery() {// 不分组 聚合查询NativeSearchQuery build = new NativeSearchQueryBuilder().addAggregation(AggregationBuilders.avg("ageAvg").field("age")).addAggregation(AggregationBuilders.sum("ageSum").field("age")).addAggregation(AggregationBuilders.max("ageMax").field("age")).addAggregation(AggregationBuilders.min("ageMin").field("age")).withPageable(PageRequest.of(0,1)) // 应该设置为0,因为只需要聚合数据,但无赖有校验设置不了.build();SearchHits<EsTest> search = elasticsearchRestTemplate.search(build, EsTest.class);log.info("match all-> 总数量:{} 结果:{}", search.getTotalHits(),JSONObject.toJSONString(search.getAggregations()));// 先分组 在聚合NativeSearchQuery build1 = new NativeSearchQueryBuilder().addAggregation(AggregationBuilders.terms("groupBySex").field("sex").subAggregation(AggregationBuilders.avg("ageAvg").field("age")).subAggregation(AggregationBuilders.sum("ageSum").field("age")).subAggregation(AggregationBuilders.max("ageMax").field("age")).subAggregation(AggregationBuilders.min("ageMin").field("age"))).withPageable(PageRequest.of(0,1)) // 应该设置为0,因为只需要聚合数据,但无赖有校验设置不了.build();SearchHits<EsTest> search1 = elasticsearchRestTemplate.search(build1, EsTest.class);Map<String, Aggregation> map = search1.getAggregations().asMap();Aggregation groupBySex = map.get("groupBySex");log.info("打断点看吧:{}",groupBySex);}

场景查询实操

查询2023年中男、女的数量并找出对应的最大/最小年龄

    /** 查询2023年中男、女的数量并找出对应的最大/最小年龄 */@Testvoid demo1() {NativeSearchQuery build = new NativeSearchQueryBuilder().addAggregation(AggregationBuilders.terms("groupBySex").field("sex").subAggregation(AggregationBuilders.count("count").field("id")).subAggregation(AggregationBuilders.max("maxAge").field("age")).subAggregation(AggregationBuilders.min("minAge").field("age"))).withPageable(PageRequest.of(0,1)).build();SearchHits<EsTest> search = elasticsearchRestTemplate.search(build, EsTest.class);log.info("打断点查看:{}",search.getAggregations());}

查询在地址中包含 “深圳” 或者 备注中包含 “积极” 的 男性青年(18-30岁)

要求关键词高亮

/** 查询在地址中包含 "深圳" 或者 备注中包含 "积极" 的 男性青年(18-30岁),要求关键词高亮 */@Testvoid demo2() {NativeSearchQuery build = new NativeSearchQueryBuilder().withQuery(QueryBuilders.boolQuery().must(QueryBuilders.termQuery("sex","男")).must(QueryBuilders.rangeQuery("age").gte(18).lte(30)).must(QueryBuilders.boolQuery().should(QueryBuilders.matchQuery("addressLocation","深圳")).should(QueryBuilders.matchQuery("remark","积极")))).withHighlightBuilder(new HighlightBuilder().preTags("<span style='color:red'>").postTags("</span>")).withHighlightFields(new HighlightBuilder.Field("addressLocation"),new HighlightBuilder.Field("remark")).build();SearchHits<EsTest> search = elasticsearchRestTemplate.search(build, EsTest.class);log.info("总量:{} 数据:{}",search.getTotalHits(),JSONObject.toJSONString(search.getSearchHits()));}

要求根据关键字找出匹配项目标,高亮实时预览

(搜地址、名称,返回 名称+id + 地址)

/** 搜索框:要求根据关键字找出匹配项目标,高亮实时预览(搜地址、名称,返回 名称+id + 地址) */@Testvoid demo3() {NativeSearchQuery build = new NativeSearchQueryBuilder().withQuery(QueryBuilders.multiMatchQuery("林深","name","addressLocation")).withFields("id", "name","addressLocation").withHighlightBuilder(new HighlightBuilder().preTags("<span style='color:red'>").postTags("</span>")).withHighlightFields(new HighlightBuilder.Field("addressLocation"),new HighlightBuilder.Field("name")).build();SearchHits<EsTest> search = elasticsearchRestTemplate.search(build, EsTest.class);log.info("总量:{} 数据:{}",search.getTotalHits(),JSONObject.toJSONString(search.getSearchHits()));}

分别找出男、女性别中年龄最小的三个人(TOP N)

    /** 分别找出男、女性别中年龄最小的三个人(TOP N) */@Testvoid demo4() {NativeSearchQuery build = new NativeSearchQueryBuilder().addAggregation(AggregationBuilders.terms("groupBySex").field("sex").subAggregation(AggregationBuilders.topHits("top3").sort("age",SortOrder.ASC).fetchSource(new String[]{"name","sex","age"},null).size(3))).build();SearchHits<EsTest> search = elasticsearchRestTemplate.search(build, EsTest.class);log.info("打断点自己看-》总量:{} 数据:{}",search.getTotalHits(),search.getAggregations());}

查询tag中带有某些标签的或者出身地在某某地的人,按照年龄降序,并且分页

    /** 查询tag中带有某些标签的或者出身地在某某地的人,按照年龄降序,并且分页 */@Testvoid demo5() {NativeSearchQuery build = new NativeSearchQueryBuilder().withQuery(QueryBuilders.boolQuery().should(QueryBuilders.termsQuery("tag","断能能","高于动","上格心","对朗步")).should(QueryBuilders.termsQuery("birthAddress","深圳","章丘"))).withSort(SortBuilders.fieldSort("age").order(SortOrder.DESC)).withSort(SortBuilders.scoreSort().order(SortOrder.DESC)).withPageable(PageRequest.of(0,5)).build();SearchHits<EsTest> search = elasticsearchRestTemplate.search(build, EsTest.class);log.info("总量:{} 数据:{}",search.getTotalHits(),search.getSearchHits());}

总结

到了这恭喜你,你也成功的入门ES,成为了一名ES的CURD BOY,但你觉得ES就仅仅如此吗?少年加油吧,才刚开始呢!!

后面会介绍一些重点操作,以及相应的进阶理论知识,理论会偏多!

相关文章:

ES 7.6 - JAVA应用基础操作篇

ES 7.6 - JAVA应用基础操作篇 环境准备依赖配置 实体类准备使用说明索引/映射操作创建索引和映射索引和映射相关查询删除索引 文档操作插入数据更新数据删除数据批量操作 文档查询根据ID查询根据字段精准查询根据字段分词查询控制返回字段范围查询组合查询排序分页高亮搜索聚合…...

com.squareup.okhttp3:okhttp 组件安全漏洞及健康度分析

组件简介 维护者square组织许可证类型Apache License 2.0首次发布2016 年 1 月 2 日最新发布时间2023 年 4 月 23 日GitHub Star44403GitHub Fork9197依赖包5,582依赖存储库77,217 com.squareup.okhttp3:okhttp 一个开源的 HTTP 客户端库&#xff0c;可以用于 Android 和 Jav…...

【Unity的HDRP渲染管线下用Steam VR串流结合使用遇到的各种问题_SteamVR 插件和Pico串流助手】

用Steam串流VR 背景:1.项目准备:相关文档和社区资源需要下载的工具2.梳理工程渲染设置和场景烘培正确:几个概念的一些说明:1. SteamVR:2. SteamVR插件:3. OpenVR和OpenXR:4. XRI:5. Pico串流助手:6. "Mock Runtime"选项含义SteamVR插件导入配置好SteamVR Came…...

Unity——音乐、音效

在游戏运行的过程中&#xff0c;音效的播放时机与游戏当前内容密切相关&#xff0c;而且随着场景的变化、剧情的推进&#xff0c;背景音乐也需要适时切换&#xff0c;所以恰当地控制音乐和音效的播放非常重要。音乐和音效的播放、停止、切换和音量变化等&#xff0c;都需要由脚…...

Ubuntu 23.10 将首次推出基于 Flutter 的新 Ubuntu 商店

导读Ubuntu 正在升级其软件商店以提供顺滑的体验&#xff01; 随着不断发展&#xff0c;Canonical 似乎全力以赴&#xff0c;将基于 Flutter 的元素整合到 Ubuntu 中。 在前段时间 Ubuntu 23.04 发布后&#xff0c;我们见到了基于 Flutter 的安装程序 &#xff0c;现在&#x…...

linux scatterlist阅读三

sg_copy_buffer 函数定义&#xff1a; /*** sg_copy_buffer - Copy data between a linear buffer and an SG list* sgl: The SG list* nents: Number of SG entries* buf: Where to copy from* buflen: The number of bytes to copy* skip: Number of bytes to sk…...

2023新,centos7安装mysql8.0.25

2023新&#xff0c;centos7安装mysql8.0.25 目录 2023新&#xff0c;centos7安装mysql8.0.251、下载rpm文件2、安装3、配置my.cnf4、启动查看重启服务5、登入mysql并修改密码6、修改可以远程登录 1、下载rpm文件 进入到你想要的文件地址下 wget https://repo.mysql.com//mysq…...

Data Rescue Professional for Mac:专业的数据恢复工具

在数字化时代&#xff0c;我们的生活和工作离不开电脑和存储设备。但是&#xff0c;意外情况时常发生&#xff0c;例如误删除文件、格式化硬盘、病毒攻击等&#xff0c;这些都可能导致重要的数据丢失。面对数据丢失&#xff0c;我们迫切需要一款可靠的数据恢复工具。今天&#…...

新手小白想要做好跨境电商独立站,需要考虑哪些要素?

对于不少中小卖家而言&#xff0c;利用独立站出海已然成为下一个跨境热潮。但是采用独立站模式做出海生意前&#xff0c;卖家需要考虑哪些要素&#xff1f; 产品选择 对于国内的卖家来说&#xff0c;依托于国内强大的供应链优势&#xff0c;只要能把握住消费者心态&#xff0…...

Consul原理介绍

官方文档&#xff1a;https://www.consul.io/docs Raft动画演示&#xff1a;http://thesecretlivesofdata.com/raft/ 注册中心对比 Consul特点 服务发现、健康检查、Key/Value存储、安全服务通信&#xff08;TLS证书&#xff09;、多数据中心 架构 角色 数据中心 数据中心内…...

【C++实战】C++实现贪吃蛇(含源代码)—基于easyx图形库

食用指南&#xff1a;本文在有C基础的情况下食用更佳 &#x1f340;本文前置知识&#xff1a;C基础 ♈️今日夜电波&#xff1a;toge—あよ 0:36 ━━━━━━️&#x1f49f;──────── 4:03 &a…...

PHP获取两个日期之间的所有日期

下面是一个示例代码&#xff0c;用于计算给定开始和结束日期之间的所有日期&#xff1a; <?phpfunction getDatesBetween($start_date, $end_date) {// 初始化结果数组$dates array();// 将开始日期转换为时间戳$current_date strtotime($start_date);$end_date strtot…...

STL之stack(适配器讲解以及双端队列的讲解)

很多人在听到适配器的时候&#xff0c;应该都是懵的&#xff0c;因为对适配器的理解都是懵懵懂懂&#xff0c;其实他很好理解&#xff0c;就是相当于一个转换器。我们可以这样理解&#xff0c;就是现实当中是的插排一样&#xff0c;上面有三个孔的&#xff0c;也有两个孔的&…...

JVM解密: 解构类加载与GC垃圾回收机制

文章目录 一. JVM内存划分二. 类加载机制1. 类加载过程2. 双亲委派模型 三. GC垃圾回收机制1. 找到需要回收的内存1.1 哪些内存需要回收&#xff1f;1.2 基于引用计数找垃圾(Java不采取该方案)1.3 基于可达性分析找垃圾(Java采取方案) 2. 垃圾回收算法2.1 标记-清除算法2.2 标记…...

【Spring Boot】Spring Boot结合MyBatis简单实现学生信息管理模块

实战&#xff1a;实现学生信息管理模块 环境准备 JDKSpring BootMyBatis 创建Spring Boot项目 使用Spring Initializr创建一个新的Spring Boot项目&#xff0c;并添加以下依赖&#xff1a; Spring WebMyBatis FrameworkMySQL Driver 数据库设计 在MySQL数据库中创建一个名…...

【Java List与Map】List<T> Map与Map List<T>的区别(126)

List&#xff1c;T&#xff1e; Map&#xff1a;List里面的数据类型包含Map&#xff1b; Map List&#xff1c;T&#xff1e;&#xff1a;Map里面value的数据类型包含List&#xff1b; 测试案例&#xff1a; import java.util.ArrayList; import java.util.HashMap; import j…...

【FreeRTOS】常用函数总结

xTaskCreate()&#xff1a; 用法&#xff1a; xTaskCreate(taskFunction, taskName, stackSize, parameters, priority, taskHandle)参数&#xff1a; taskFunction&#xff1a;任务函数&#xff0c;即任务的入口函数。taskName&#xff1a;任务的名称。stackSize&#xff1a;任…...

The Cherno——OpenGL

The Cherno——OpenGL 1. 欢迎来到OpenGL OpenGL是一种跨平台的图形接口&#xff08;API&#xff09;&#xff0c;就是一大堆我们能够调用的函数去做一些与图像相关的事情。特殊的是&#xff0c;OpenGL允许我们访问GPU&#xff08;Graphics Processing Unit 图像处理单元&…...

linux中学习控制进程的要点

1. 进程创建 1.1 fork函数 #include <unistd.h> pid_t fork(void); 返回值&#xff1a;自进程中返回0&#xff0c;父进程返回子进程id&#xff0c;出错返回-1 进程调用fork&#xff0c;当控制转移到内核中的fork代码后&#xff0c;内核会做以下操作 分配新的内存块和…...

C++Qt QSS要注意的坑

qss源自css&#xff0c;相当于css的一个子集&#xff0c;主要支持的是css2标准&#xff0c;很多网上的css3的标准的写法在qss这里是不生效的&#xff0c;所以不要大惊小怪。 qss也不是完全支持所有的css2&#xff0c;比如text-align官方文档就有说明&#xff0c;只支持 QPushB…...

LeetCode每日一题:56. 合并区间(2023.8.27 C++)

目录 56. 合并区间 题目描述&#xff1a; 实现代码与解析&#xff1a; 排序 贪心 原理思路&#xff1a; 56. 合并区间 题目描述&#xff1a; 以数组 intervals 表示若干个区间的集合&#xff0c;其中单个区间为 intervals[i] [starti, endi] 。请你合并所有重叠的区间&…...

电视盒子什么牌子好?经销商整理线下热销电视盒子品牌排行榜

在面对众多品牌和型号时&#xff0c;不知道电视盒子哪个牌子好的消费者超多&#xff0c;很多人进店都会问我电视盒子哪款好&#xff1f;我根据店铺内近两年的销量情况整理了电视盒子品牌排行榜&#xff0c;看看实体店哪些电视盒子最值得入手吧。 TOP 1.泰捷WEBOX 40Pro Max电视…...

JavaScript关于函数的小挑战

题目 回到两个体操队&#xff0c;即海豚队和考拉队! 有一个新的体操项目&#xff0c;它的工作方式不同。 每队比赛3次&#xff0c;然后计算3次得分的平均值&#xff08;所以每队有一个平均分&#xff09;。 只有当一个团队的平均分至少是另一个团队的两倍时才会获胜。否则&…...

机器学习深度学习——针对序列级和词元级应用微调BERT

&#x1f468;‍&#x1f393;作者简介&#xff1a;一位即将上大四&#xff0c;正专攻机器学习的保研er &#x1f30c;上期文章&#xff1a;机器学习&&深度学习——NLP实战&#xff08;自然语言推断——注意力机制实现&#xff09; &#x1f4da;订阅专栏&#xff1a;机…...

重启Mysql时报错rm: cannot remove ‘/var/lock/subsys/mysql‘: Permission denied

只有用mysql重启时报错&#xff0c;用root不报错 [mysqlt3-dtpoc-dtpoc-web04 bin]$ service mysql restart Shutting down MySQL.. SUCCESS! rm: cannot remove /var/lock/subsys/mysql: Permission denied Starting MySQL.. SUCCESS! [roott3-dtpoc-dtpoc-web04 ~]# serv…...

[C/C++]指针详讲-让你不在害怕指针

个人主页&#xff1a;北海 &#x1f390;CSDN新晋作者 &#x1f389;欢迎 &#x1f44d;点赞✍评论⭐收藏✨收录专栏&#xff1a;C/C&#x1f91d;希望作者的文章能对你有所帮助&#xff0c;有不足的地方请在评论区留言指正&#xff0c;大家一起学习交流&#xff01;&#x1f9…...

无涯教程-Android - Frame Layout函数

Frame Layout 旨在遮挡屏幕上的某个区域以显示单个项目&#xff0c;通常&#xff0c;应使用FrameLayout来保存单个子视图&#xff0c;因为在子视图彼此不重叠的情况下&#xff0c;难以以可扩展到不同屏幕尺寸的方式组织子视图。 不过&#xff0c;您可以使用android:layout_grav…...

docker desktop安装es 并连接elasticsearch-head:5

首先要保证docker安装成功&#xff0c;打开cmd&#xff0c;输入docker -v&#xff0c;出现如下界面说明安装成功了 下面开始安装es 第一步&#xff1a;拉取es镜像 docker pull elasticsearch:7.6.2第二步&#xff1a;运行容器 docker run -d --namees7 --restartalways -p 9…...

计网(第四章)(网络层)(六)

目录 一、路由选择协议&#xff08;动态路由自动获取路由信息&#xff09;概述&#xff1a; 二、因特网采用的路由协议 主要特点&#xff1a; 1.自适应 2.分布式 3.分层次 因特网采用分层次的路由选择协议&#xff1a; 三、常见的路由选择协议 一、路由选择协议&#xff…...

科研无人机平台P600进阶版,突破科研难题!

随着无人机技术日益成熟&#xff0c;无人机的应用领域不断扩大&#xff0c;对无人机研发的需求也在不断增加。然而&#xff0c;许多开发人员面临着无法从零开始构建无人机的时间和精力压力&#xff0c;同时也缺乏适合的软件平台来支持他们的开发工作。为了解决这个问题&#xf…...