首页 > 其他分享 >ES - RestClient 查询文档

ES - RestClient 查询文档

时间:2023-09-30 20:22:42浏览次数:36  
标签:hits RestClient void hotel client 文档 ES

目录

快速入门

@SpringBootTest
class SearchfDocTest {

    private RestHighLevelClient client;


    //查询所有文档
    @Test
    public void testMatchAll() throws IOException {
        //1. 准备请求对象
        SearchRequest searchRequest = new SearchRequest("hotel");
        //2. 准备DSL
       searchRequest.source().query(QueryBuilders.matchAllQuery());
        //3. 发送请求
        SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT);

        //4. 解析响应解锁
        SearchHits hits = response.getHits();
        //4.1 获取搜索到的总条数
        long value = hits.getTotalHits().value;
        System.out.println("共搜索到" + value + "条数据");
        SearchHit[] hitsArr = hits.getHits();
        for (SearchHit hit : hits) {
            //获取文档soure
            String sourceAsString = hit.getSourceAsString();
            //反序列化
            HotelDoc hotel = JSON.parseObject(sourceAsString, HotelDoc.class);
            System.out.println(hotel);
        }
    }

    @BeforeEach
    void setUp() {
        this.client = new RestHighLevelClient(RestClient.builder(
                HttpHost.create("http://192.168.184.152:9200")
        ));
    }
    @AfterEach
    void tearDown() throws IOException {
        this.client.close();
    }
}

标签:hits,RestClient,void,hotel,client,文档,ES
From: https://www.cnblogs.com/czzz/p/17738170.html

相关文章

  • 沁恒·蓝牙Mesh之中心节点
    1.中心节点示例代码解读voidApp_Init(void)vendor_model_cli_init(vnd_models)传入参数vnd_models的来源及其数据类型模型初始化需要传入一个蓝牙mesh模型实例vendor_model_cli_init(vnd_models);vendor_model_cli是自定义模型数据类型blemesh_on_sync()主要是对Mesh......
  • 柔性生产线MES系统的应用实施
    柔性生产线MES系统的应用实施-模具管理软件丨电子MES丨MES系统厂家丨汽车零部件MES系统苏州微缔软件股份有限公司官网http://www.videasoft.com/hangyexinwen/897.html柔性生产线MES系统的应用实施发布时间:2023-02-10作者:videasoft   近年来,随着JIT(JustInTime)、B......
  • Codeforces Round 900 (Div. 3)
    目录写在前面ABCDEFG写在最后写在前面比赛地址:https://codeforces.com/contest/1878。前天晚上他妈睡不着觉又不想看漫画打游戏于是到阳台上开把div3放松心情。40min过了5题把剩下两题都口了感觉没意思了于是睡觉。太菜了还是,现在是div3随便AK但是div2过不了E的......
  • vue:el-table在resize时报错([email protected])
    一,报错信息:Uncaughtruntimeerrors:×ERRORResizeObserverloopcompletedwithundeliverednotifications.athandleError(webpack-internal:///./node_modules/webpack-dev-server/client/overlay.js:299:58)ateval(webpack-internal:///./node_modules/webpa......
  • jenkins教程:解决nodejs前端构建时报错(EMFILE: too many open files)
    修改系统最大打开文件数临时生效ulimit-n65535永久生效vim/etc/security/limits.conf*softnofile65535*hardnofile65535#修改单个进程最大打开文件数*softnprocunlimited*hardnprocunlimited查看修改结果ulimit-n配置完成后,restartjenkins即可生效。或者临时......
  • layuiAdmin pro v1.x 【单页版】开发者文档
    layuiAdminstdv1.x【iframe版】开发者文档题外该文档适用于layuiAdmin专业版(单页面),阅读之前请务必确认是否与你使用的版本对应。熟练掌握layuiAdmin的前提是熟练掌握layui,因此除了本篇文档,layui的文档也是必不可少的存在。看云上的文档快速上手部署解压文件......
  • Remove Old ST03N Data after System Refresh(转)
    SymptomAfterasystemrefresh/systemcopy,thetransactioncodeST03Nisshowingtheolddatafromthesourcesystem.Solution1.RefertoSAPNote1179929ThedatafromothersystemscanbedeletedfromthetablesSWNCMONIandSWNCMONIINDEXusingthefu......
  • 洛谷题解 | AT_abc321_c Primes on Interval
    目录题目翻译题目描述输入格式输出格式样例#1样例输入#1样例输出#1样例#2样例输入#2样例输出#2样例#3样例输入#3样例输出#3题目简化题目思路AC代码题目翻译【题目描述】你决定用素数定理来做一个调查.众所周知,素数又被称为质数,其含义就是除了数字一和本身之外不能......
  • 29、Flink SQL之DESCRIBE、EXPLAIN、USE、SHOW、LOAD、UNLOAD、SET、RESET、JAR、JOB
    Flink系列文章1、Flink部署、概念介绍、source、transformation、sink使用示例、四大基石介绍和示例等系列综合文章链接13、Flink的tableapi与sql的基本概念、通用api介绍及入门示例14、Flink的tableapi与sql之数据类型:内置数据类型以及它们的属性15、Flink的tableap......
  • Educational Codeforces Round 122 (Rated for Div. 2)
    A.Div.7#include<bits/stdc++.h>usingnamespacestd;voidsolve(){intn,a,b,c;cin>>n;c=n%10,n/=10;b=n%10,n/=10;a=n%10,n/=10;intres,val=100;for(inti=0;i<=9......