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

Es集成Springboot

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

一、下載ES

ES:下載中心 - Elastic 中文社區(qū)

springboot es集成,ES,elasticsearch,大數(shù)據(jù),搜索引擎

?安裝需要JDK,JAVA_HOME
ElasticSearch下載并解壓,進(jìn)入bin目錄,雙擊elasticsearch.bat就能啟動(dòng),訪問(wèn)地址localhost:9200

?springboot es集成,ES,elasticsearch,大數(shù)據(jù),搜索引擎

?注:本文使用的的ES版本為7.17.0

二、創(chuàng)建springboot項(xiàng)目,引入依賴

         <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-high-level-client</artifactId>
            <version>7.4.2</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>7.4.2</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-client</artifactId>
            <version>7.4.2</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>5.4.6</version>
        </dependency>

三、新建ES配置,注入RestHighLevelClient 客戶端

@Configuration
public class ElasticSearchClientConfig {
    @Bean
    public RestHighLevelClient restHighLevelClient(){
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(new HttpHost("127.0.0.1",9200,"http"))
        );
        return client;
    }
}

四、測(cè)試索引API

 @Autowired
    @Qualifier("restHighLevelClient")
    public RestHighLevelClient client;


    @Test
    void testCreateIndex() throws Exception{
       //創(chuàng)建索引請(qǐng)求
        CreateIndexRequest request = new CreateIndexRequest("xr_index");
        //客戶端執(zhí)行請(qǐng)求,獲得響應(yīng)
        CreateIndexResponse response = client.indices().create(request, RequestOptions.DEFAULT);
        System.out.println(JSONUtil.toJsonStr(response));
    }
    //測(cè)試索引的是否存在
    @Test
    void testExistIndex() throws Exception {
        GetIndexRequest request= new GetIndexRequest("xr_index");
        boolean exist = client.indices().exists(request, RequestOptions.DEFAULT);
        System.out.println(exist);
    }
    //刪除索引
    @Test
    void testDeleteIndex() throws Exception {
        DeleteIndexRequest request= new DeleteIndexRequest("xr_index");
        AcknowledgedResponse response = client.indices().delete(request, RequestOptions.DEFAULT);
        System.out.println(JSONUtil.toJsonStr(response));
    }

五、測(cè)試測(cè)試文檔API

 //添加文檔
    @Test
    void testAddDocument() throws Exception {
        Map<String, String> hashMap = new HashMap<>();
        hashMap.put("name","雪人");
        hashMap.put("age","22");
        //創(chuàng)建請(qǐng)求
        IndexRequest request = new IndexRequest("bai_index");
        //規(guī)則 put/bai_index/_doc/1
        request.id("2");
        request.timeout(TimeValue.timeValueSeconds(1));
        //放入數(shù)據(jù)
        request.source(JSONUtil.toJsonStr(hashMap), XContentType.JSON);
        //發(fā)送請(qǐng)求
        IndexResponse response = client.index(request, RequestOptions.DEFAULT);
        System.out.println(JSONUtil.toJsonStr(response));
    }
    //測(cè)試文檔是否存在
    @Test
    void   testExitDocument() throws Exception{
        GetRequest request = new GetRequest("xr_index", "2");
        boolean exists = client.exists(request, RequestOptions.DEFAULT);
        System.out.println(exists);
    }

    //測(cè)試獲取文檔
    @Test
    void testGetDocument() throws  Exception{
        GetRequest request = new GetRequest("xr_index", "2");
        GetResponse response = client.get(request, RequestOptions.DEFAULT);
        System.out.println(response.getSourceAsString());
    }

    //測(cè)試修改文檔
    @Test
    void testUpdateDocument() throws  Exception{
        UpdateRequest request = new UpdateRequest("xr", "2");
        request.timeout(TimeValue.timeValueSeconds(1));
        Map<String, String> hashMap = new HashMap<>();
        hashMap.put("name","獨(dú)自堆雪人");
        hashMap.put("age","22");

        request.doc(JSONUtil.toJsonStr(hashMap),XContentType.JSON);
        UpdateResponse response = client.update(request, RequestOptions.DEFAULT);
        System.out.println(JSONUtil.toJsonStr(response));
    }
  //測(cè)試刪除文檔
    @Test
    void testDeleteDocument() throws Exception {
        DeleteRequest request= new DeleteRequest("獨(dú)自堆雪人","2");
         request.timeout(TimeValue.timeValueSeconds(1));
        DeleteResponse response = client.delete(request, RequestOptions.DEFAULT);
        System.out.println(response.status());
    }
    //測(cè)試添加文檔
    @Test
    void testBulkAddDocument() throws Exception {
        BulkRequest request = new BulkRequest();
         request.timeout(TimeValue.timeValueSeconds(1));

        List<Object> userlist=new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            Map<String, String> hashMap = new HashMap<>();
            hashMap.put("name","bai"+i);
            hashMap.put("age",""+i);
            userlist.add(hashMap);
        }
        //批量處理請(qǐng)求   (下面如果不設(shè)置id就會(huì)隨機(jī)生成一個(gè)id)
        for (int i = 0; i < userlist.size(); i++) {
            request.add(
                    new IndexRequest("bai_index")
                            .id(""+(i+1))
                            .source(JSONUtil.toJsonStr(userlist.get(i)),XContentType.JSON)
            );
        }
        BulkResponse response = client.bulk(request, RequestOptions.DEFAULT);
        System.out.println(response.hasFailures());//返回false表示添加成功
    }

    //測(cè)試查詢文檔
    @Test
    void testSearchDocument() throws Exception {
        SearchRequest request = new SearchRequest("bai_index");
        //構(gòu)建搜索條件
        SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
        sourceBuilder.highlighter();
        TermQueryBuilder termQueryBuilder = QueryBuilders.termQuery("name", "bai1");
        sourceBuilder.query(termQueryBuilder);
        sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));

        request.source(sourceBuilder);
        SearchResponse response = client.search(request, RequestOptions.DEFAULT);
        System.out.println(JSONUtil.toJsonStr(response.getHits()));
        System.out.println("=====================");
        for (SearchHit documentFields : response.getHits().getHits()) {
            System.out.println(documentFields.getSourceAsMap());
        }
    }

注意ES版本與引入ES客戶端對(duì)應(yīng),否則會(huì)出現(xiàn)一些api調(diào)用兼容問(wèn)題。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-522163.html

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

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(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)文章

  • ElasticSearch內(nèi)容分享(四):ES搜索引擎

    ElasticSearch內(nèi)容分享(四):ES搜索引擎

    目錄 ES搜索引擎 1. DSL設(shè)置查詢條件 1.1 DSL查詢分類 1.2 全文檢索查詢 1.2.1 使用場(chǎng)景 1.2.2 match查詢 1.2.3 mulit_match查詢 1.3 精準(zhǔn)查詢 1.3.1 term查詢 1.3.2 range查詢 1.4 地理坐標(biāo)查詢 1.4.1 矩形范圍查詢 1.4.2 附近(圓形)查詢 1.5 復(fù)合查詢 1.5.0 復(fù)合查詢歸納 1.5.1 相關(guān)性算分 1.5.2 算分函數(shù)查

    2024年02月05日
    瀏覽(24)
  • 使用Logstash同步mysql數(shù)據(jù)到Elasticsearch(親自踩坑)_將mysql中的數(shù)據(jù)導(dǎo)入es搜索引擎利用logstash(1)

    使用Logstash同步mysql數(shù)據(jù)到Elasticsearch(親自踩坑)_將mysql中的數(shù)據(jù)導(dǎo)入es搜索引擎利用logstash(1)

    先自我介紹一下,小編浙江大學(xué)畢業(yè),去過(guò)華為、字節(jié)跳動(dòng)等大廠,目前阿里P7 深知大多數(shù)程序員,想要提升技能,往往是自己摸索成長(zhǎng),但自己不成體系的自學(xué)效果低效又漫長(zhǎng),而且極易碰到天花板技術(shù)停滯不前! 因此收集整理了一份《2024年最新大數(shù)據(jù)全套學(xué)習(xí)資料》,

    2024年04月28日
    瀏覽(26)
  • 入門ElasticSearch :為什么選擇ES作為搜索引擎?

    隨著數(shù)據(jù)量的不斷增長(zhǎng),搜索和分析大規(guī)模數(shù)據(jù)集變得越來(lái)越重要。傳統(tǒng)數(shù)據(jù)庫(kù)在面對(duì)這種需求時(shí)往往表現(xiàn)不佳,這時(shí)候就需要一種專門用于搜索和分析的引擎。ElasticSearch (簡(jiǎn)稱ES)就是這樣一款強(qiáng)大的搜索引擎,它具有許多優(yōu)勢(shì),使得它成為許多企業(yè)和開發(fā)者的首選。 簡(jiǎn)

    2024年02月09日
    瀏覽(23)
  • elasticsearch(ES)分布式搜索引擎01——(初識(shí)ES,索引庫(kù)操作和文檔操作,RestClient操作索引庫(kù)和文檔)

    elasticsearch(ES)分布式搜索引擎01——(初識(shí)ES,索引庫(kù)操作和文檔操作,RestClient操作索引庫(kù)和文檔)

    1.1.1.elasticsearch的作用 elasticsearch是一款非常強(qiáng)大的開源搜索引擎,具備非常多強(qiáng)大功能,可以幫助我們從海量數(shù)據(jù)中快速找到需要的內(nèi)容 1.1.2.ELK技術(shù)棧 elasticsearch結(jié)合kibana、Logstash、Beats,也就是elastic stack(ELK)。被廣泛應(yīng)用在日志數(shù)據(jù)分析、實(shí)時(shí)監(jiān)控等領(lǐng)域: 而elasticsearc

    2024年02月07日
    瀏覽(48)
  • 搜索引擎elasticsearch :安裝elasticsearch (包含安裝組件kibana、IK分詞器、部署es集群)

    搜索引擎elasticsearch :安裝elasticsearch (包含安裝組件kibana、IK分詞器、部署es集群)

    kibana可以幫助我們方便地編寫DSL語(yǔ)句,所以還要裝kibana 因?yàn)槲覀冞€需要部署kibana容器,因此需要讓es和kibana容器互聯(lián)。這里先創(chuàng)建一個(gè)網(wǎng)絡(luò): 這里我們采用elasticsearch的7.12.1版本的鏡像,這個(gè)鏡像體積非常大,接近1G。不建議大家自己pull。 課前資料提供了鏡像的tar包: 大家將

    2024年02月16日
    瀏覽(26)
  • Elasticsearch (ES) 搜索引擎: 搜索功能:搜索分頁(yè)、搜索匹配、全文搜索、搜索建議、字段排序

    原文鏈接:https://xiets.blog.csdn.net/article/details/132348920 版權(quán)聲明:原創(chuàng)文章禁止轉(zhuǎn)載 專欄目錄:Elasticsearch 專欄(總目錄) ES 搜索 API 官網(wǎng)文檔:Search APIs 先創(chuàng)建一個(gè)索引,并寫入一些文檔用于搜索示例: 寫入一些文檔示例: 官網(wǎng)API:The _source option 搜索結(jié)果中的文檔數(shù)據(jù)封裝

    2024年02月08日
    瀏覽(33)
  • 搜索引擎ElasticSearch分布式搜索和分析引擎學(xué)習(xí),SpringBoot整合ES個(gè)人心得

    搜索引擎ElasticSearch分布式搜索和分析引擎學(xué)習(xí),SpringBoot整合ES個(gè)人心得

    Elasticsearch是一個(gè)基于Lucene的搜索服務(wù)器。它提供了一個(gè)分布式多用戶能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java語(yǔ)言開發(fā)的,并作為Apache許可條款下的開放源碼發(fā)布,是一種流行的企業(yè)級(jí)搜索引擎。Elasticsearch用于云計(jì)算中,能夠達(dá)到實(shí)時(shí)搜索,穩(wěn)定,可靠,

    2024年02月04日
    瀏覽(34)
  • es Elasticsearch 六 java api spirngboot 集成es

    es Elasticsearch 六 java api spirngboot 集成es

    目錄 Java restApi Springboot 集成es 新增-同步 新增-異步 增刪改查流程 _bulk 批量操作 新增-同步 新增-異步 增刪改查流程 創(chuàng)建請(qǐng)求、2.執(zhí)行、3.查看返回結(jié)果 ? ? _bulk 批量操作 ok 持續(xù)更新

    2024年02月10日
    瀏覽(26)
  • 初識(shí)Elasticsearch——GO集成ES

    初識(shí)Elasticsearch——GO集成ES

    Elasticsearch是一個(gè)分布式文檔存儲(chǔ)。Elasticsearch存儲(chǔ)的是序列化為JSON文檔的復(fù)雜數(shù)據(jù)結(jié)構(gòu),而不是以行列數(shù)據(jù)的形式存儲(chǔ)的信息。當(dāng)集群中有多個(gè)Elasticsearch節(jié)點(diǎn)時(shí),存儲(chǔ)的文檔分布在整個(gè)集群中,可以立即從任何節(jié)點(diǎn)訪問(wèn)。 當(dāng)存儲(chǔ)文檔時(shí),它幾乎是實(shí)時(shí)的——在1秒內(nèi)就可以被

    2024年02月03日
    瀏覽(25)
  • Elasticsearch (ES) 搜索引擎: 文本搜索:分析器/分詞器、同義詞/停用詞、拼音搜索、高亮顯示、拼寫糾錯(cuò)

    原文鏈接:https://xiets.blog.csdn.net/article/details/132349032 版權(quán)聲明:原創(chuàng)文章禁止轉(zhuǎn)載 專欄目錄:Elasticsearch 專欄(總目錄) 文本搜索主要指的就是全文搜索,全文搜索是搜索引擎的核心功能,與精確匹配的結(jié)構(gòu)化數(shù)據(jù)不同,文本(text)數(shù)據(jù)在構(gòu)建索引和搜索時(shí)都需要進(jìn)行額外的處

    2024年02月03日
    瀏覽(44)

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

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

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

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包