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

springboot整合elasticsearch8組合條件查詢

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

整合過程見上一篇文章
springboot整合elasticsearch8文章來源地址http://www.zghlxwxcb.cn/news/detail-598235.html

1.es8多條件組合查詢
@Slf4j
@RestController
@RequestMapping("/elastic")
public class ElasticSearchTestController {

    @Autowired
    private ElasticsearchClient client;
    
     @GetMapping("/user")
    public List getUser() throws IOException {

        List<User> userList = new ArrayList<>();
        String name = "張三";

        // 構(gòu)建查詢條件
        List<Query> queryList = new ArrayList<>();
        
        // MatchPhraseQuery
        Query byName = MatchPhraseQuery.of(m -> m
                .field("name")
                .query(name)
        )._toQuery();

        // RangeQuery
        Query byAge1 = RangeQuery.of(r -> r
                .field("age")
                .gte(JsonData.of(10))
        )._toQuery();

        Query byAge2 = RangeQuery.of(r -> r
                .field("age")
                .lte(JsonData.of(13))
        )._toQuery();

        // TermsQuery
        List<FieldValue> ls = new ArrayList<>();
        ls.add(FieldValue.of("男"));
        ls.add(FieldValue.of("女"));
        Query termsQuery = TermsQuery.of(t ->t.field("sex").terms(terms ->terms.value(ls)))._toQuery();

        queryList.add(byName);
        queryList.add(byAge1);
        queryList.add(byAge2);
        queryList.add(termsQuery);

        String[] sources = new String[]{"name", "age"};

        SearchResponse<User> response = client.search(s -> s
                        .index("user").query(q -> q.bool(b -> b.must(queryList)))
                        .sort(sort -> sort.field(f -> f.field("age").order(SortOrder.Asc)))     //排序
                        .source(sc -> sc                                                        //查詢字段過濾
                                .filter(f -> f
                                        .includes(Arrays.asList(sources))
                                )
                        )
                        .from(0)                                                                 //分頁
                        .size(10),                                            
                User.class
        );

        List<Hit<User>> hits = response.hits().hits();
        for (Hit<User> hit: hits) {
            userList.add(hit.source());
        }
        return  userList;
    }
}
2.使用scroll進行大數(shù)據(jù)量查詢
 		...
		// 第一次查詢
		SearchResponse<User> response = client.search(s -> s
                        .index("user")
                        .query(q -> q.bool(b -> b.must(queryList)))                                                             
                        .size(5000)
                        .scroll(t ->t.time("5m")),                                               //開啟scroll
                User.class
        );

        List<Hit<User>> hits = response.hits().hits();
        for (Hit<User> hit: hits) {
            userList.add(hit.source());
        }
        String scrollId = response.scrollId();
        List<String> strings = new ArrayList<>();
        strings.add(scrollId);
        ScrollResponse<User> search = null;

        do {
            String scrollIdTemp = scrollId;
            log.info(scrollIdTemp);
            search = client.scroll(s->s.scrollId(scrollIdTemp).scroll(t->t.time("5m")),User.class);
            for (Hit<User> hit : search.hits().hits()) {
                userList.add(hit.source());
            }
            scrollId = search.scrollId();
            strings.add(scrollId);
        }while(!search.hits().hits().isEmpty());
        // 清除scrollId
        client.clearScroll(c->c.scrollId(strings));
        ...      

到了這里,關(guān)于springboot整合elasticsearch8組合條件查詢的文章就介紹完了。如果您還想了解更多內(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)文章

  • ElasticSearch8 - SpringBoot整合ElasticSearch

    springboot 整合 ES 有兩種方案,ES 官方提供的 Elasticsearch Java API Client 和 spring 提供的 [Spring Data Elasticsearch](Spring Data Elasticsearch) 兩種方案各有優(yōu)劣 Spring:高度封裝,用著舒服。缺點是更新不及時,有可能無法使用 ES 的新 API ES 官方:更新及時,靈活,缺點是太靈活了,基本是一

    2024年03月25日
    瀏覽(78)
  • springboot整合elasticsearch8

    1.引入maven依賴 2.application.yml添加配置 3.編寫config文件 啟動demo項目,通過控制臺日志查看是否能夠正常連接es。 4.在DemoApplicationTests編寫簡單測試操作es。

    2024年02月12日
    瀏覽(22)
  • springBoot整合ElasticSearch8.x版本

    導(dǎo)入依賴 ? dependency ? ? ? ? groupIdcom.fasterxml.jackson.core/groupId ? ? ? ? artifactIdjackson-databind/artifactId ? ? ? ? version2.13.2/version ? /dependency ? ? dependency ? ? ? ? groupIdorg.glassfish/groupId ? ? ? ? artifactIdjakarta.json/artifactId ? ? ? ? version2.0.1/version ? /dependency ? ? ? ? ? dependency ?

    2023年04月21日
    瀏覽(28)
  • SpringBoot3.0 整合 ElasticSearch8.5.0 及使用

    這兩個版本都是目前較新的版本,本文選用的依賴是 spring-boot-starter-data-elasticsearch:3.0 ,這個新版本也是改用了es的 elasticsearch-java API,全面推薦使用Lambda語法;另外SpringData本身推出了 Repository 功能(有些類似Mybatis-Plus)的功能,也支持注解簡化開發(fā)。 Docker 快速部署 單機 ela

    2024年02月11日
    瀏覽(22)
  • 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.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日
    瀏覽(28)
  • Springboot3.1+Elasticsearch8.x匹配查詢

    Springboot3.1+Elasticsearch8.x匹配查詢

    springboot-starter3.1.0中spring-data-elasticsearch的版本為5.1.0,之前很多方法和類都找不到了。這里主要講講在5.1.0版本下如何使用spring data對elesticsearch8.x進行匹配查詢。 第一步當(dāng)然是配置依賴 在這里面,spring-boot-starter-data-elasticsearch是3.1.0的,里面的spring-data-elasticsearch是5.1.0的,服務(wù)

    2024年02月15日
    瀏覽(23)
  • 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)
  • Elasticsearch8.8.0 SpringBoot實戰(zhàn)操作各種案例(索引操作、聚合、復(fù)雜查詢、嵌套等)

    Elasticsearch8.8.0 全網(wǎng)最新版教程 從入門到精通 通俗易懂 引入依賴 添加配置文件 application.yaml 導(dǎo)入ca證書到項目中 從任意一個es容器中,拷貝證書到resources目錄下 [外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-EXytUrDp-1691330960034)(media/16912196423122/16

    2024年02月13日
    瀏覽(29)

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

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

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

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包