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

Resthighlevelclient被棄用后,ES 8.x 最新用法 java api

這篇具有很好參考價(jià)值的文章主要介紹了Resthighlevelclient被棄用后,ES 8.x 最新用法 java api。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

一、ES 8.x 整合springBoot

1、導(dǎo)入依賴(lài)
<dependency>
	<groupId>com.fasterxml.jackson.core</groupId>
	<artifactId>jackson-databind</artifactId>
	<version>2.12.3</version>
</dependency>

<dependency>
	<groupId>co.elastic.clients</groupId>
	<artifactId>elasticsearch-java</artifactId>
	<version>8.7.1</version>
</dependency>
2、創(chuàng)建 ElasticsearchClient
@Configuration
public class ElasticsearchClientConfig {
    @Bean
    public ElasticsearchClient restHighLevelClient() {
        RestClient restClient = RestClient.builder(
                new HttpHost("localhost", 9200)
        ).build();
        ElasticsearchTransport elasticsearchTransport = new RestClientTransport(restClient,new JacksonJsonpMapper());

        return new ElasticsearchClient(elasticsearchTransport);
    }
}

二、ES java api

1、搜索

    @Resource
    ElasticsearchClient elasticsearchClient;
    @Test
    void contextLoads() throws IOException {
        // 指定索引,設(shè)置查詢(xún)語(yǔ)句 
        SearchRequest searchRequest = 
            new SearchRequest.Builder().index("demo_comment_message")
            .query(Query.of(t -> t.bool(
                s -> s.must(
                        k -> k.match(
                                v -> v.field("desc").query("第一"))
                ).must(v-> v.range(m ->m.field("diggCount").lte(JsonData.of(100))))
        ))).build();
        // 執(zhí)行查詢(xún)語(yǔ)句
        SearchResponse<Object> search = elasticsearchClient.search(searchRequest,Object.class);
		// 獲取返回結(jié)果
        for (Hit<Object> hit : search.hits().hits()) {
            System.out.println(hit.source());
        }
    }

2、單個(gè)插入(更新)文檔

    @Resource
    ElasticsearchClient elasticsearchClient;

    @Test
    void contextLoads() throws IOException {
      IndexRequest<Product> indexRequest = 
          new IndexRequest.Builder<Product()
          .index("demo_comment_message") // 索引
          .id(product.getVideoId())  // 指定文檔Id  也可以不指定,使用ES 自己生成的Id
          .document(product).build();  // 文檔內(nèi)容 (product) 
        // 運(yùn)行插入語(yǔ)句
        IndexResponse index = elasticsearchClient.index(indexRequest);
        System.out.println(indexRequest.toString());
    }

3、批量插入(更新)文檔文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-624373.html

   @Resource
   ElasticsearchClient elasticsearchClient;

   @Test
   void contextLoads() throws IOException {
       // 構(gòu)建插入 List
       List<Product> productList = new ArrayList<>();

       for (int i = 3; i < 10; i++) {
           Product product = new Product();
           product.setCommentId("Demo_" + i);
           product.setDesc("第" + i + "次 測(cè)試");
           product.setDiggCount(i * 10L);
           product.setVideoId("Code_" + i);
           productList.add(product);
       }

       BulkRequest.Builder builder = new BulkRequest.Builder().index("demo_comment_message"); // 指定索引
       
       for (Product product : productList) {
           builder.operations(op -> op.index(in -> in.id(product.getVideoId()).document(product)));
       }
       // 運(yùn)行批量操作
       BulkResponse bulk = elasticsearchClient.bulk(builder.build());
       System.out.println(bulk.errors()); // 返回 false 即為成功 
   }

到了這里,關(guān)于Resthighlevelclient被棄用后,ES 8.x 最新用法 java api的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

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

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

相關(guān)文章

  • vscode | linux | c++ intelliense 被棄用解決方案

    vscode | linux | c++ intelliense 被棄用解決方案

    每日一句,vscode用的爽是爽,主要是可配置太強(qiáng)了。如果也很會(huì)研究,可以直接去咸魚(yú)接單了 廢話(huà)少說(shuō),直接整。 用著用著說(shuō)是c++ intelliense被棄用,很多輔助功能無(wú)法使用,像查看定義、查看引用、函數(shù)跳轉(zhuǎn)、智能提示…… 歸根結(jié)底,還是太菜了,但真的很需要這些輔助啊

    2024年02月12日
    瀏覽(79)
  • Android Handler被棄用,那么以后怎么使用Handler,或者類(lèi)似的功能

    Android Handler被棄用,那么以后怎么使用Handler,或者類(lèi)似的功能

    Android API30左右,Android應(yīng)用在使用傳統(tǒng)寫(xiě)法使用Handler類(lèi)的時(shí)候會(huì)顯示刪除線(xiàn),并提示相關(guān)的方法已經(jīng)被棄用,不建議使用。 Android studio中的顯示和建議: 看下官方API關(guān)于此處的解釋?zhuān)??簡(jiǎn)要說(shuō)就是如果在實(shí)例化Handler的時(shí)候不提供Looper, 可能導(dǎo)致操作丟失(Handler 沒(méi)有預(yù)估到新

    2023年04月21日
    瀏覽(26)
  • WebSecurityConfigurerAdapter被棄用Spring Security基于組件化的配置和使用

    WebSecurityConfigurerAdapter被棄用Spring Security基于組件化的配置和使用

    在Spring Security 5.7及之后的版本中 WebSecurityConfigurerAdapter 將被啟用,安全框架將轉(zhuǎn)向基于組件的安全配置。 spring security官方文檔 Spring Security without the WebSecurityConfigurerAdapter 如果使用的Spring Boot版本高于低于2.7.0、Spring Security版本高于5.7,就會(huì)出現(xiàn)如下的提示: 1、被啟用的原因

    2024年02月02日
    瀏覽(23)
  • Unity打包APK錯(cuò)誤:‘a(chǎn)ndroid.enableR8‘選項(xiàng)已被棄用,不應(yīng)再使用

    Unity打包APK錯(cuò)誤:\\\'android.enableR8’選項(xiàng)已被棄用,不應(yīng)再使用 在Unity游戲開(kāi)發(fā)中,我們經(jīng)常需要將游戲打包成APK文件以在A(yíng)ndroid設(shè)備上進(jìn)行測(cè)試或發(fā)布。然而,有時(shí)候在打包APK的過(guò)程中,可能會(huì)遇到一些錯(cuò)誤。其中一個(gè)常見(jiàn)的錯(cuò)誤是 “The option ‘a(chǎn)ndroid.enableR8’ is deprecated and sh

    2024年02月08日
    瀏覽(93)
  • Python錯(cuò)題集-7:DeprecationWarning: Conversion of an array with ndim(被棄用警告)

    Python錯(cuò)題集-7:DeprecationWarning: Conversion of an array with ndim(被棄用警告)

    DeprecationWarning: Conversion of an array with ndim 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.) ? X[i] = np.random.normal(loc=Ex, scale=np.abs(Enn), size=1) DeprecationWarning: Conversion of an array with ndim ?是一個(gè)警告,通常出

    2024年04月09日
    瀏覽(33)
  • iOS中獲取MCC和MNC的方法及iOS 16中CTCarrier被棄用的替代方案

    一、使用公共API獲取MCC和MNC 在iOS中,我們可以使用CoreTelephony框架來(lái)獲取用戶(hù)的移動(dòng)國(guó)家代碼(MCC)和移動(dòng)網(wǎng)絡(luò)代碼(MNC)。具體操作步驟如下: 在Xcode項(xiàng)目中,點(diǎn)擊項(xiàng)目目標(biāo),進(jìn)入“General”選項(xiàng)卡,在“Frameworks, Libraries, and Embedded Content”下點(diǎn)擊“+”按鈕,搜索并添加 Cor

    2024年02月11日
    瀏覽(84)
  • ES聚合查詢(xún) 基于RestHighLevelClient依賴(lài) Java操作

    一、介紹 (偏自我理解) ? ? ? ? 1.ES聚合查詢(xún)通用流程 ? ? ? ? ? ? ? ? 1.分組 ( 好比Mysql --- group by ) ? ? ? ? ? ? ? ? 2.組內(nèi)聚合 也叫 組內(nèi)指標(biāo)( 好比Mysql --- SUM()、COUNT()、AVG()、MAX()、MIN() ) ? ? ? ? 2.桶(我要是es開(kāi)發(fā)者,我起名叫啥都行) ? ? ? ? ? ? ? ? 1.滿(mǎn)足特

    2024年02月06日
    瀏覽(17)
  • Java使用Springboot集成Es官方推薦(RestHighLevelClient)

    Java使用Springboot集成Es官方推薦(RestHighLevelClient)

    SpringBoot集成ElasticSearch的四種方式(主要講解ES官方推薦方式) TransportClient:這種方式即將棄用 官方將在8.0版本徹底去除 Data-Es:Spring提供的封裝的方式,由于是Spring提供的,所以每個(gè)SpringBoot版本對(duì)應(yīng)的ElasticSearch,具體這么個(gè)對(duì)應(yīng)的版本,自己去官網(wǎng)看 ElasticSearch SQL:將Elasti

    2023年04月08日
    瀏覽(23)
  • 【Elasticsearch學(xué)習(xí)筆記五】es常用的JAVA API、es整合SpringBoot項(xiàng)目中使用、利用JAVA代碼操作es、RestHighLevelClient客戶(hù)端對(duì)象

    目錄 一、Maven項(xiàng)目集成Easticsearch 1)客戶(hù)端對(duì)象 2)索引操作 3)文檔操作 4)高級(jí)查詢(xún) 二、springboot項(xiàng)目集成Spring Data操作Elasticsearch 1)pom文件 2)yaml 3)數(shù)據(jù)實(shí)體類(lèi) 4)配置類(lèi) 5)Dao數(shù)據(jù)訪(fǎng)問(wèn)對(duì)象 6)索引操作 7)文檔操作 8)文檔搜索 三、springboot項(xiàng)目集成bboss操作elasticsearch

    2023年04月09日
    瀏覽(37)
  • Java(102):ES7.14,RestHighLevelClient創(chuàng)建索引時(shí)報(bào)錯(cuò) create is deprecated

    Java(102):ES7.14,RestHighLevelClient創(chuàng)建索引時(shí)報(bào)錯(cuò) create is deprecated

    一、Maven引用 二、遇到問(wèn)題:ES7.14,RestHighLevelClient創(chuàng)建索引時(shí)報(bào)錯(cuò) create? is deprecated \\\'create(org.elasticsearch.action.admin.indices.create.CreateIndexRequest, org.elasticsearch.client.RequestOptions)\\\' is deprecated? ?出現(xiàn)原因?: 這是因?yàn)樵谑褂胏reate方法時(shí) , 會(huì)有兩個(gè)選擇 , 其中一個(gè)已經(jīng)過(guò)時(shí)了 client.indic

    2023年04月09日
    瀏覽(21)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包