9 RestClient客户端操作文档

2024-06-24 08:28

本文主要是介绍9 RestClient客户端操作文档,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1. match_all

@GetMapping("matchAll")public void matchAll() throws IOException {//1. 准备requestSearchRequest request = new SearchRequest("hotel");//2. 组织DSL参数request.source().query(QueryBuilders.matchAllQuery());SearchResponse response = restHighLevelClient.search(request, RequestOptions.DEFAULT);//3.解析结果SearchHits searchHits = response.getHits();//4. 查询总条数long value = searchHits.getTotalHits().value;System.out.println("总条数: " + value);//5.  数据SearchHit[] hits = searchHits.getHits();for (SearchHit hit: hits) {String json = hit.getSourceAsString();System.out.println(json);}}
2024-06-24 00:57:38.000  INFO 8968 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2024-06-24 00:57:38.000  INFO 8968 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2024-06-24 00:57:38.000  INFO 8968 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 0 ms
总条数: 4
{"address":"柳州东路1号","brand":"如家","business":"弘阳商圈","city":"南京市浦口区","id":1,"location":"33.33,131.33","name":"如家","pic":"http://www.bai.com/images/rujia.png","price":189,"score":7,"starName":"二星"}
{"address":"月华西路2号","brand":"7天","business":"江宁商圈","city":"南京市江宁区","id":2,"location":"33.33,131.35","name":"7天","pic":"http://www.bai.com/images/7.png","price":188,"score":7,"starName":"二星"}
{"address":"洪武北路1号","brand":"四季","business":"新街口商圈","city":"南京市玄武区","id":3,"location":"33.35,131.36","name":"四季","pic":"http://www.bai.com/images/7.png","price":489,"score":8,"starName":"3星"}
{"address":"是单独发2号","brand":"四季如春","business":"新街口商圈","city":"南京市鼓楼区","id":4,"location":"66.66,133.36","name":"四季如春","pic":"http://www.qiniu.com/images/xxx.png","price":999,"score":9,"starName":"五星"}

2.全文检索查询

单字段查询
//单字段查询@GetMapping("singleMatch")public void singleMatch() throws IOException {//1. 准备requestSearchRequest request = new SearchRequest("hotel");//2. 组织DSL参数request.source().query(QueryBuilders.matchQuery("name","四季如春"));SearchResponse response = restHighLevelClient.search(request, RequestOptions.DEFAULT);//3.解析结果SearchHits searchHits = response.getHits();//4. 查询总条数long value = searchHits.getTotalHits().value;System.out.println("总条数: " + value);//5.  数据SearchHit[] hits = searchHits.getHits();for (SearchHit hit: hits) {String json = hit.getSourceAsString();System.out.println(json);}}

name搜索字段参与了分词,因此会查询出两条记录

2024-06-24 01:12:58.956  INFO 7784 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2024-06-24 01:12:58.957  INFO 7784 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : Completed initialization in 1 ms
总条数: 2
{"address":"是单独发2号","brand":"四季如春","business":"新街口商圈","city":"南京市鼓楼区","id":4,"location":"66.66,133.36","name":"四季如春","pic":"http://www.qiniu.com/images/xxx.png","price":999,"score":9,"starName":"五星"}
{"address":"洪武北路1号","brand":"四季","business":"新街口商圈","city":"南京市玄武区","id":3,"location":"33.35,131.36","name":"四季","pic":"http://www.bai.com/images/7.png","price":489,"score":8,"starName":"3星"}
2024-06-24 01:13:29.036 ERROR 7784 --- [rRegistryThread] c.xxl.job.core.util.XxlJobRemotingUtil   : Connection refused: connect

多字段查询

//多字段查询@GetMapping("multiMatch")public void multiMatch() throws IOException {//1. 准备requestSearchRequest request = new SearchRequest("hotel");//2. 组织DSL参数request.source().query(QueryBuilders.multiMatchQuery("四季如春","name","brand"));SearchResponse response = restHighLevelClient.search(request, RequestOptions.DEFAULT);//3.解析结果SearchHits searchHits = response.getHits();//4. 查询总条数long value = searchHits.getTotalHits().value;System.out.println("总条数: " + value);//5.  数据SearchHit[] hits = searchHits.getHits();for (SearchHit hit: hits) {String json = hit.getSourceAsString();System.out.println(json);}}
2024-06-24 01:15:22.728  INFO 4552 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2024-06-24 01:15:22.730  INFO 4552 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 2 ms
总条数: 2
{"address":"是单独发2号","brand":"四季如春","business":"新街口商圈","city":"南京市鼓楼区","id":4,"location":"66.66,133.36","name":"四季如春","pic":"http://www.qiniu.com/images/xxx.png","price":999,"score":9,"starName":"五星"}
{"address":"洪武北路1号","brand":"四季","business":"新街口商圈","city":"南京市玄武区","id":3,"location":"33.35,131.36","name":"四季","pic":"http://www.bai.com/images/7.png","price":489,"score":8,"starName":"3星"}
2024-06-24 01:15:43.546 ERROR 4552 --- [rRegistryThread] c.xxl.job.core.util.XxlJobRemotingUtil   : Connection refused: connect

term查询

@GetMapping("term")public void term() throws IOException {//1. 准备requestSearchRequest request = new SearchRequest("hotel");//2. 组织DSL参数request.source().query(QueryBuilders.termQuery("city","南京市浦口区"));SearchResponse response = restHighLevelClient.search(request, RequestOptions.DEFAULT);//3.解析结果SearchHits searchHits = response.getHits();//4. 查询总条数long value = searchHits.getTotalHits().value;System.out.println("总条数: " + value);//5.  数据SearchHit[] hits = searchHits.getHits();for (SearchHit hit: hits) {String json = hit.getSourceAsString();System.out.println(json);}}
2024-06-24 01:19:07.854  INFO 6212 --- [nio-8080-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2024-06-24 01:19:07.854  INFO 6212 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2024-06-24 01:19:07.855  INFO 6212 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : Completed initialization in 1 ms
总条数: 1
{"address":"柳州东路1号","brand":"如家","business":"弘阳商圈","city":"南京市浦口区","id":1,"location":"33.33,131.33","name":"如家","pic":"http://www.bai.com/images/rujia.png","price":189,"score":7,"starName":"二星"}

range范围查询

@GetMapping("range")public void range() throws IOException {//1. 准备requestSearchRequest request = new SearchRequest("hotel");//2. 组织DSL参数request.source().query(QueryBuilders.rangeQuery("price").gte(200).lt(500));SearchResponse response = restHighLevelClient.search(request, RequestOptions.DEFAULT);//3.解析结果SearchHits searchHits = response.getHits();//4. 查询总条数long value = searchHits.getTotalHits().value;System.out.println("总条数: " + value);//5.  数据SearchHit[] hits = searchHits.getHits();for (SearchHit hit: hits) {String json = hit.getSourceAsString();System.out.println(json);}}
2024-06-24 01:21:50.603  INFO 8916 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2024-06-24 01:21:50.604  INFO 8916 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 1 ms
总条数: 1
{"address":"洪武北路1号","brand":"四季","business":"新街口商圈","city":"南京市玄武区","id":3,"location":"33.35,131.36","name":"四季","pic":"http://www.bai.com/images/7.png","price":489,"score":8,"starName":"3星"}

bool复合查询

@GetMapping("boolQuery")public void boolQuery() throws IOException {//1. 准备requestSearchRequest request = new SearchRequest("hotel");//2. 组织DSL参数BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();//添加must条件boolQuery.must(QueryBuilders.termQuery("city","南京市浦口区"));//添加filter条件boolQuery.filter(QueryBuilders.rangeQuery("price").lt(200));request.source().query(boolQuery);SearchResponse response = restHighLevelClient.search(request, RequestOptions.DEFAULT);//3.解析结果SearchHits searchHits = response.getHits();//4. 查询总条数long value = searchHits.getTotalHits().value;System.out.println("总条数: " + value);//5.  数据SearchHit[] hits = searchHits.getHits();for (SearchHit hit: hits) {String json = hit.getSourceAsString();System.out.println(json);}}
2024-06-24 01:26:50.886  INFO 15052 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2024-06-24 01:26:50.886  INFO 15052 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 0 ms
总条数: 1
{"address":"柳州东路1号","brand":"如家","business":"弘阳商圈","city":"南京市浦口区","id":1,"location":"33.33,131.33","name":"如家","pic":"http://www.bai.com/images/rujia.png","price":189,"score":7,"starName":"二星"}
2024-06-24 01:27:15.288 ERROR 15052 --- [rRegistryThread] c.xxl.job.core.util.XxlJobRemotingUtil   : Connection refused: connect

这篇关于9 RestClient客户端操作文档的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1089628

相关文章

RedHat运维-Linux文本操作基础-AWK进阶

你不用整理,跟着敲一遍,有个印象,然后把它保存到本地,以后要用再去看,如果有了新东西,你自个再添加。这是我参考牛客上的shell编程专项题,只不过换成了问答的方式而已。不用背,就算是我自己亲自敲,我现在好多也记不住。 1. 输出nowcoder.txt文件第5行的内容 2. 输出nowcoder.txt文件第6行的内容 3. 输出nowcoder.txt文件第7行的内容 4. 输出nowcode

SQL Server中,always on服务器的相关操作

在SQL Server中,建立了always on服务,可用于数据库的同步备份,当数据库出现问题后,always on服务会自动切换主从服务器。 例如192.168.1.10为主服务器,12为从服务器,当主服务器出现问题后,always on自动将主服务器切换为12,保证数据库正常访问。 对于always on服务器有如下操作: 1、切换主从服务器:假如需要手动切换主从服务器时(如果两个服务

JavaWeb系列二十: jQuery的DOM操作 下

jQuery的DOM操作 CSS-DOM操作多选框案例页面加载完毕触发方法作业布置jQuery获取选中复选框的值jQuery控制checkbox被选中jQuery控制(全选/全不选/反选)jQuery动态添加删除用户 CSS-DOM操作 获取和设置元素的样式属性: css()获取和设置元素透明度: opacity属性获取和设置元素高度, 宽度: height(), widt

PS的一些操作~持续抄袭中....

套索工具使用时移动图片——按住空格键,鼠标左键按住,拖动!

基于Java医院药品交易系统详细设计和实现(源码+LW+调试文档+讲解等)

💗博主介绍:✌全网粉丝10W+,CSDN作者、博客专家、全栈领域优质创作者,博客之星、平台优质作者、专注于Java、小程序技术领域和毕业项目实战✌💗 🌟文末获取源码+数据库🌟 感兴趣的可以先收藏起来,还有大家在毕设选题,项目以及论文编写等相关问题都可以给我留言咨询,希望帮助更多的人  Java精品实战案例《600套》 2023-2025年最值得选择的Java毕业设计选题大全:1000个热

帆软报表常用操作

欢迎来到我的博客,代码的世界里,每一行都是一个故事 🎏:你只管努力,剩下的交给时间 🏠 :小破站 帆软报表常用操作 多序号实现使用数据集作为参数空白页或者竖线页修改页面Title金额,或者保留两位小数等等设置日期格式显示图片使用公式 多序号实现 所用函数为SEQ(),如果一张报表中需要用到多个序号,那么就需要加入参数SEQ(1),SEQ(

【zabbix】zabbix客户端配置

1、部署zabbix客户端 #zabbix 5.0 版本采用 golang 语言开发的新版本客户端 agent2 。#zabbix 服务端 zabbix_server 默认使用 10051 端口,客户端 zabbix_agent2 默认使用 10050 端口。systemctl disable --now firewalldsetenforce 0hostnamectl set-host

工程文档CAD转换必备!在 Java 中将 DWG 转换为 JPG

Aspose.CAD 是一个独立的类库,以加强Java应用程序处理和渲染CAD图纸,而不需要AutoCAD或任何其他渲染工作流程。该CAD类库允许将DWG, DWT, DWF, DWFX, IFC, PLT, DGN, OBJ, STL, IGES, CFF2文件、布局和图层高质量地转换为PDF和光栅图像格式。 Aspose API支持流行文件格式处理,并允许将各类文档导出或转换为固定布局文件格

BD错误集锦5——java.nio.file.FileSystemException 客户端没有所需的特权

问题:在运行storm本地模式程序时,java.nio.file.FileSystemException  客户端没有所需的特权   解决方式:以管理员身份运行IDEA即可。