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

ES(Elasticsearch)+SpringBoot實(shí)現(xiàn)分頁(yè)查詢(xún)

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

1.ES介紹

??ES作為一個(gè)搜索工具,寄托于Lucene之上,提供了方便的數(shù)據(jù)存儲(chǔ)和搜索服務(wù),一般的用它來(lái)作為網(wǎng)頁(yè)數(shù)據(jù)索引以及存儲(chǔ)用戶畫(huà)像(即用戶標(biāo)簽)數(shù)據(jù),可以提供復(fù)具有復(fù)雜的查詢(xún)條件的服務(wù)。例如在網(wǎng)頁(yè)索引中,通過(guò)倒排的方式索引的方式,對(duì)文檔進(jìn)行分詞存儲(chǔ),可以很快的定位關(guān)鍵字所在的文檔,從而達(dá)到毫秒級(jí)的搜索效率;而在用戶畫(huà)像存儲(chǔ)中,ES既可以作為標(biāo)簽寬表,提供類(lèi)似HIVE寬表的特性,又可以達(dá)到傳統(tǒng)關(guān)系型數(shù)據(jù)庫(kù)或者HBase的實(shí)時(shí)查詢(xún)的要求,所以在一般的用戶畫(huà)像存儲(chǔ)中也是不二之選。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-574475.html

2.引入依賴(lài)

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-high-level-client</artifactId>
            <version>7.8.0</version>
        </dependency>

3.配置客戶端進(jìn)行連接

package com.lantu.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RestClientConfig {


    //配置RestHighLevelClient依賴(lài)到spring容器中待用
    @Bean
    public RestHighLevelClient restHighLevelClient(){
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(
                        //綁定本機(jī),端口,協(xié)議,如果是ES集群,就配置多個(gè)
                        new HttpHost("127.0.0.1",9200,"http")));
        return client;
    }
}

4.編寫(xiě)接口并實(shí)現(xiàn)分頁(yè)查詢(xún)

    @ApiOperation("ES快搜")
    @GetMapping("/wen")
    public Result<Map<String,Object>> getProblemList(@RequestParam(value = "wenti") String wenti,
                                                @RequestParam(value = "pageNo",required = false) Integer pageNo,
                                                @RequestParam(value = "pageSize") Integer pageSize) throws IOException {

        SearchRequest searchRequest = new SearchRequest("problem");
        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
        searchSourceBuilder.query(QueryBuilders.matchPhraseQuery("wenti", wenti).analyzer("ik_max_word"));

        //過(guò)濾查詢(xún)
        String[] excludes = {};
        String[] includes = {"wenti","lab","id"};
        searchSourceBuilder.fetchSource(includes, excludes);

        searchSourceBuilder.from(pageNo);
        searchSourceBuilder.size(pageSize);

        searchRequest.source(searchSourceBuilder);

        SearchResponse response = client.search(searchRequest,RequestOptions.DEFAULT);
        SearchHits hits = response.getHits();
        List<Problem> problemList=new ArrayList<>();
        Map<String,Object> data = new HashMap<>();

        for (SearchHit hit : hits) {
            problemList.add(JSON.parseObject(hit.getSourceAsString(),Problem.class));
            System.out.println(hit.getSourceAsString());
        }

        data.put("total",hits.getTotalHits());
        data.put("rows",problemList);
        return Result.success(data);
    }

到了這里,關(guān)于ES(Elasticsearch)+SpringBoot實(shí)現(xiàn)分頁(yè)查詢(xún)的文章就介紹完了。如果您還想了解更多內(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)文章

  • Springboot集成ElasticSearch實(shí)現(xiàn)簡(jiǎn)單的crud、簡(jiǎn)單分頁(yè)、模糊查詢(xún)

    Springboot集成ElasticSearch實(shí)現(xiàn)簡(jiǎn)單的crud、簡(jiǎn)單分頁(yè)、模糊查詢(xún)

    pom.xml引入ElasticSearch application.yml配置 啟動(dòng)類(lèi)加入注解@EnableElasticsearchRepositories ElasticSearchEntity Repository類(lèi)繼承ElasticsearchRepository ElasticSearchService ElasticSearchController 測(cè)試 查看創(chuàng)建的索引(相當(dāng)于MySQL的表) method:GET 刪除索引 method:DELETE 查看索引里的全部數(shù)據(jù), elastic是實(shí)體類(lèi)

    2023年04月18日
    瀏覽(25)
  • SpringBoot整合Elasticsearch實(shí)現(xiàn)分頁(yè)條件查詢(xún)及注意事項(xiàng)

    項(xiàng)目環(huán)境: springboot 2.3.7.RELEASE es 6.8.3 這里需要注意es中日期格式,ES默認(rèn)是不支持yyyy-MM-dd HH:mm:ss格式的,需要通過(guò) @Field(type = FieldType.Date, format = DateFormat.custom,pattern = \\\"yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_second\\\") 來(lái)指定日期格式。 直接看業(yè)務(wù)層實(shí)現(xiàn)分頁(yè)條件查詢(xún): 范圍查詢(xún): es en

    2023年04月16日
    瀏覽(22)
  • Elasticsearch ES操作:查詢(xún)數(shù)據(jù)(全部、分頁(yè)、單條)

    查詢(xún) 條件查詢(xún) 指定條數(shù) 返回結(jié)果

    2024年02月16日
    瀏覽(25)
  • ElasticSearch系列 - SpringBoot整合ES:實(shí)現(xiàn)分頁(yè)搜索 from+size、search after、scroll

    01. 數(shù)據(jù)準(zhǔn)備 ElasticSearch 向 my_index 索引中索引了 12 條文檔: 02. ElasticSearch 如何查詢(xún)所有文檔? ElasticSearch 查詢(xún)所有文檔 根據(jù)查詢(xún)結(jié)果可以看出,集群中總共有12個(gè)文檔,hits.total.value=12, 但是在 hits 數(shù)組中只有 10 個(gè)文檔。如何才能看到其他的文檔? 03. ElasticSearch 如何指定搜

    2023年04月08日
    瀏覽(29)
  • Springboot整合Elasticsearch新版分頁(yè)查詢(xún)

    其它插入、刪除、簡(jiǎn)單查詢(xún)都可以通過(guò)Repository調(diào)用方法查詢(xún)。 Elasticsearch現(xiàn)在的新版本已經(jīng)棄用了ElasticsearchTemplate類(lèi),Repository里原來(lái)的search方法也已經(jīng)棄用了。下面是使用ElasticsearchRestTemplate類(lèi)實(shí)現(xiàn)的分頁(yè)查詢(xún) 代碼

    2024年02月11日
    瀏覽(16)
  • ElasticSearch第六講 ES 三種分頁(yè)查詢(xún)from+size / Scroll /search_after

    我的Git地址:https://gitee.com/ITLULU 歡迎訪問(wèn) ES的分頁(yè)查詢(xún)和關(guān)系數(shù)據(jù)庫(kù)的分頁(yè)查詢(xún)的區(qū)別: ES分頁(yè)查詢(xún)有以下幾種: 1:簡(jiǎn)單的 from size (有默認(rèn)的最大Size,不可無(wú)限大小查詢(xún),因?yàn)閿?shù)據(jù)過(guò)多查詢(xún)性能會(huì)降低,且也要考慮內(nèi)存問(wèn)題,以及OS緩存數(shù)據(jù)的能力) 2: scroll基于查詢(xún)窗口

    2024年02月01日
    瀏覽(15)
  • 【ElasticSearch】JavaRestClient實(shí)現(xiàn)文檔查詢(xún)、排序、分頁(yè)、高亮

    【ElasticSearch】JavaRestClient實(shí)現(xiàn)文檔查詢(xún)、排序、分頁(yè)、高亮

    先初始化JavaRestClient對(duì)象: 代碼和DSL對(duì)應(yīng)上就是: 運(yùn)行結(jié)果: 然后是對(duì)結(jié)果的解析,對(duì)照響應(yīng)結(jié)果: 示例代碼: 運(yùn)行結(jié)果: 總結(jié): 構(gòu)建DSL是通過(guò)HighLevelRestClient中的resource()方法來(lái)實(shí)現(xiàn)的,這里包含了查詢(xún)、排序、分頁(yè)、高亮等操作 構(gòu)建查詢(xún)條件的核心部分,即查詢(xún)類(lèi)型,

    2024年02月14日
    瀏覽(30)
  • elasticSearch 實(shí)現(xiàn)分頁(yè)查詢(xún)(過(guò)萬(wàn)跳頁(yè)實(shí)現(xiàn)方案)

    from size 分頁(yè)(存在1W數(shù)據(jù)上限限制,當(dāng)然也可以釋放) scroll 滾動(dòng)查詢(xún) search_after 分頁(yè)查詢(xún) from size 支持跳頁(yè)的偽分頁(yè)查詢(xún) 前三種分頁(yè)方式就不給出具體的實(shí)現(xiàn)了,這里主要講解第四種 《from size 支持跳頁(yè)的偽分頁(yè)查詢(xún)》

    2024年02月11日
    瀏覽(11)
  • ElasticSearch系列 - SpringBoot整合ES:組合多個(gè)查詢(xún)條件 bool 查詢(xún)

    01. ElasticSearch 布爾查詢(xún)是什么? 在實(shí)際應(yīng)用中,我們很有可能會(huì)查詢(xún)多個(gè)值或字段。 一個(gè) bool 查詢(xún)由三部分組成: must:所有的語(yǔ)句都必須(must) 匹配,與 AND 等價(jià)。 must_not:所有的語(yǔ)句都不能(must not)匹配,與 NOT 等價(jià)。 should:至少有一個(gè)語(yǔ)句要匹配,與 OR 等價(jià)。 02.

    2023年04月08日
    瀏覽(28)
  • ElasticSearch序列 - SpringBoot整合ES:范圍查詢(xún) range

    01. ElasticSearch range查詢(xún)是什么? Elasticsearch 中的 range 查詢(xún)可以用于查詢(xún)某個(gè)字段在一定范圍內(nèi)的文檔。 range 查詢(xún)可同時(shí)提供包含和不包含這兩種范圍表達(dá)式,可供組合的選項(xiàng)如下: gt : 大于(greater than) lt : 小于(less than) gte : = 大于或等于(greater than or equal to) lte : = 小于

    2024年02月09日
    瀏覽(28)

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

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

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

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包