国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

springBoot整合ElasticSearch8.x版本

這篇具有很好參考價值的文章主要介紹了springBoot整合ElasticSearch8.x版本。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

導(dǎo)入依賴

? <dependency>
? ? ? ? <groupId>com.fasterxml.jackson.core</groupId>
? ? ? ? <artifactId>jackson-databind</artifactId>
? ? ? ? <version>2.13.2</version>
? </dependency>
?
? <dependency>
? ? ? ? <groupId>org.glassfish</groupId>
? ? ? ? <artifactId>jakarta.json</artifactId>
? ? ? ? <version>2.0.1</version>
? </dependency>
? ? ? ?
? <dependency>
? ? ? ? <groupId>co.elastic.clients</groupId>
? ? ? ? <artifactId>elasticsearch-java</artifactId>
? ? ? ? <version>8.1.0</version>
? </dependency>

配置

@Configuration
public class ElasticSearchConfig {
? ? @Bean
? ? public ElasticsearchClient elasticsearchClient(){
? ? ? ? RestClient client = RestClient.builder(new HttpHost("localhost", 9200,"http")).build();
? ? ? ? ElasticsearchTransport transport = new RestClientTransport(client,new JacksonJsonpMapper());
? ? ? ? return new ElasticsearchClient(transport);
? ? }
}

增加索引

? @Autowired
? private ElasticsearchClient client;
??
? @Test
? ? public void createTest() throws IOException {
? ? ? ??
? ? ? ? //寫法比RestHighLevelClient更加簡潔
? ? ? ? CreateIndexResponse indexResponse = client.indices().create(c -> c.index("user"));
? ? }
文章來源地址http://www.zghlxwxcb.cn/news/detail-419879.html

增加index

? @Autowired
? private ElasticsearchClient client;
??
? @Test
? ? public void createTest() throws IOException {
? ? ? ??
? ? ? ? CreateIndexResponse indexResponse = client.indices().create(c -> c.index("user"));
? ? }

查詢Index

? ? @Test
? ? public void queryTest() throws IOException {
? ? ? ? GetIndexResponse getIndexResponse = client.indices().get(i -> i.index("user"));
? ? }

?判斷index是否存在

? ? @Test
? ? public void existsTest() throws IOException {
? ? ? ? BooleanResponse booleanResponse = client.indices().exists(e -> e.index("user"));
? ? ? ? System.out.println(booleanResponse.value());
? ? }

刪除index

@Test
? ? public void deleteTest() throws IOException {
? ? ? ? DeleteIndexResponse deleteIndexResponse = client.indices().delete(d -> d.index("user"));
? ? ? ? System.out.println(deleteIndexResponse.acknowledged());
? ? }

Document CRUD

插入document?

? ? @Test
? ? public void addDocumentTest() throws IOException {
?
? ? ? ? User user = new User("user1", 10);
? ? ? ? IndexResponse indexResponse = client.index(i -> i
? ? ? ? ? ? ? ? .index("user")
?
? ? ? ? ? ? ? ? //設(shè)置id
? ? ? ? ? ? ? ? .id("1")
?
? ? ? ? ? ? ? ? //傳入user對象
? ? ? ? ? ? ? ? .document(user));
?
? ? }

?更新Document

? ? @Test
? ? public void updateDocumentTest() throws IOException {
? ? ? ? UpdateResponse<User> updateResponse = client.update(u -> u
? ? ? ? ? ? ? ? ? ? ? ? .index("user")
? ? ? ? ? ? ? ? ? ? ? ? .id("1")
? ? ? ? ? ? ? ? ? ? ? ? .doc(new User("user2", 13))
? ? ? ? ? ? ? ? , User.class);
? ? }

判斷Document是否存在

? ? @Test
? ? public void existDocumentTest() throws IOException {
? ? ? ? BooleanResponse indexResponse = client.exists(e -> e.index("user").id("1"));
? ? ? ? System.out.println(indexResponse.value());
? ? }

查詢Document

? ? @Test
? ? public void getDocumentTest() throws IOException {
? ? ? ? GetResponse<User> getResponse = client.get(g -> g
? ? ? ? ? ? ? ? ? ? ? ? .index("user")
? ? ? ? ? ? ? ? ? ? ? ? .id("1")
? ? ? ? ? ? ? ? , User.class
? ? ? ? );
? ? ? ? System.out.println(getResponse.source());
? ? }

刪除Document

? ? @Test
? ? public void deleteDocumentTest() throws IOException {
? ? ? ? DeleteResponse deleteResponse = client.delete(d -> d
? ? ? ? ? ? ? ? .index("user")
? ? ? ? ? ? ? ? .id("1")
? ? ? ? );
? ? ? ? System.out.println(deleteResponse.id());
? ? }

批量插入Document

? ? @Test
? ? public void bulkTest() throws IOException {
? ? ? ? List<User> userList = new ArrayList<>();
? ? ? ? userList.add(new User("user1", 11));
? ? ? ? userList.add(new User("user2", 12));
? ? ? ? userList.add(new User("user3", 13));
? ? ? ? userList.add(new User("user4", 14));
? ? ? ? userList.add(new User("user5", 15));
? ? ? ? List<BulkOperation> bulkOperationArrayList = new ArrayList<>();
? ? ? ? //遍歷添加到bulk中
? ? ? ? for(User user : userList){
? ? ? ? ? ? bulkOperationArrayList.add(BulkOperation.of(o->o.index(i->i.document(user))));
? ? ? ? }
? ? ?
? ? ? ? BulkResponse bulkResponse = client.bulk(b -> b.index("user")
? ? ? ? ? ? ? ? .operations(bulkOperationArrayList));
?
? ? }

?查詢

? ? @Test
? ? public void searchTest() throws IOException {
? ? ? ? SearchResponse<User> search = client.search(s -> s
? ? ? ? ? ? ? ? .index("user")
? ? ? ? ? ? ? ? //查詢name字段包含hello的document(不使用分詞器精確查找)
? ? ? ? ? ? ? ? .query(q -> q
? ? ? ? ? ? ? ? ? ? ? ? .term(t -> t
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? .field("name")
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? .value(v -> v.stringValue("hello"))
? ? ? ? ? ? ? ? ? ? ? ? ))
? ? ? ? ? ? ? ? //分頁查詢,從第0頁開始查詢3個document
? ? ? ? ? ? ? ? .from(0)
? ? ? ? ? ? ? ? .size(3)
? ? ? ? ? ? ? ? //按age降序排序
? ? ? ? ? ? ? ? .sort(f->f.field(o->o.field("age").order(SortOrder.Desc))),User.class
? ? ? ? );
? ? ? ? for (Hit<User> hit : search.hits().hits()) {
? ? ? ? ? ? System.out.println(hit.source());
? ? ? ? }
? ? }

到了這里,關(guān)于springBoot整合ElasticSearch8.x版本的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • java-springboot整合ElasticSearch8.2復(fù)雜查詢

    近期有大數(shù)據(jù)項目需要用到es,而又是比較新的es版本,網(wǎng)上也很少有8.x的java整合教程,所有寫下來供各位參考。 首先 1.導(dǎo)包: 2.客戶端連接代碼EsUtilConfigClint: 一開始按照其他博主的方法,長時間連接不操作查詢再次調(diào)用查詢時會報錯timeout,所以要設(shè)置RequestConfigCallback 3

    2024年02月11日
    瀏覽(16)
  • SpringBoot3整合Elasticsearch8.x之全面保姆級教程

    SpringBoot3整合Elasticsearch8.x之全面保姆級教程

    安裝配置 ES : https://blog.csdn.net/qq_50864152/article/details/136724528 安裝配置 Kibana : https://blog.csdn.net/qq_50864152/article/details/136727707 新建項目:新建名為 web 的 SpringBoot3 項目 公共配置 介紹:一個開源的高擴展的分布式全文檢索引擎,可以近乎實時的存儲 和檢索數(shù)據(jù) 依賴: web 模塊

    2024年04月13日
    瀏覽(27)
  • elasticsearch8和kibana部署以及與springboot整合遇到的坑

    elasticsearch8和kibana部署以及與springboot整合遇到的坑

    我本來使用的是最新版本的es 8.6.2。但是由于ik分詞器只更新到8.6.1,所以就更改為部署8.6.1。在過程中遇到一些問題,這里做一個總結(jié) 環(huán)境:windows10 elasticsearch版本:8.6.1 一、修改es 用戶密碼的方式 二、kibana 使用用戶名和密碼登錄 修改kibana.yml 文件 啟動kibana一直閃退 解決方

    2024年02月02日
    瀏覽(22)
  • springboot3整合elasticsearch8.7.0實現(xiàn)為bean對象創(chuàng)建索引添加映射

    springboot3整合elasticsearch8.7.0實現(xiàn)為bean對象創(chuàng)建索引添加映射

    目錄 準備工作 添加相關(guān)依賴 在yml中配置elasticsearch 主要內(nèi)容 實體類 ElasticSearch配置類 測試 確認當(dāng)前沒有counter索引 啟動spring 再次查詢counter索引? 在測試類中輸出counter索引的映射 官方文檔 要注意版本對應(yīng)關(guān)系 spring官方文檔中有版本對照表 目前我使用的都是最新的版本,

    2024年02月03日
    瀏覽(20)
  • 關(guān)于springboot整合elasticsearch8.4.3的找不到相關(guān)類JsonProvider、JsonProvider的解決方案

    關(guān)于springboot整合elasticsearch8.4.3的找不到相關(guān)類JsonProvider、JsonProvider的解決方案

    環(huán)境是springboot是2.3.7,elasticsearch是8.4.3 關(guān)于8.4.3的官方文檔:https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/8.4/installation.html 創(chuàng)建ElasticsearchClient 對象: 一開始報錯ClassNotFoundException: jakarta.json.spi.JsonProvider,然后看了下官方文檔修改了下jakarta.json-api的版本.解決完成之后

    2024年02月02日
    瀏覽(26)
  • springboot整合elasticsearch8.2報錯unable to parse response body for Response{requestLine

    springboot整合elasticsearch8.2報錯unable to parse response body for Response{requestLine

    用postman發(fā)出請求,執(zhí)行saveAll命令的時候發(fā)現(xiàn)錯誤,返回500。 但是很奇怪elsticsearch卻能夠存進去。版本的話springboot是2.6.4,2.7貌似也不行 查看:官方資料 我們使用savaall會去繼承ElasticsearchRepository類,并調(diào)用其中的函數(shù)。 然而,據(jù)圖可知,在2022.8月依舊只支持7.17.4,而我的版本

    2024年02月16日
    瀏覽(23)
  • SpringBoot整合ElasticSearch版本問題

    最近在整個這兩個框架,發(fā)現(xiàn)老是版本對不上,不是缺少類,就是啟動不了,美好的一下午就這樣浪費了,多說一句廢話,es的版本更新速度也太快了,如果spring boot已經(jīng)固定的,注意一下es的版本。 下面的這個鏈接是spring官方提供的兼容版本 springboot與elasticsearch兼容版本對應(yīng)

    2024年02月15日
    瀏覽(22)
  • springboot整合elasticsearch:7.6.2版本

    ? ? ? ? es,kibana,ik的安裝可看之前的文章 ? ? ? ?docker安裝elasticsearch,kibana,ik分詞器_Give_time_to_Bug的博客-CSDN博客 ? ? ? ? elasticsearch版本與springboot版本一定要對應(yīng),否則bug極多 ????????我安裝的elasticsearch是7.6.2版本,對應(yīng)使用的springboot是2.3.2.RELEASE 接下來介紹兩種接

    2023年04月16日
    瀏覽(18)
  • springboo整合elasticSearch8 java client api

    官方文檔: https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/connecting.html gradle maven 若無密碼,可以使用下面方式: 使用es自動設(shè)置的mapping 設(shè)置mappings Doc是自定義實體類 比如 select * from doc where user_id in(1,2,3); 方式一: 方式二: 方式三:

    2024年02月13日
    瀏覽(46)
  • SpringBoot連接ElasticSearch8.*

    系統(tǒng)中需要使用到ElasticSearch進行內(nèi)容檢索,因此需要搭建SpringBoot + ElasticSearch的環(huán)境。

    2024年02月16日
    瀏覽(25)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包