当前位置: 首页 > news >正文

网站风格分析网络热词2022

网站风格分析,网络热词2022,无锡模板建站多少钱,昆山规划与建设局网站快速入门 使用RestClient客户端进行数据搜索可以分为两步 构建并发起请求 代码解读: 第一步,创建SearchRequest对象,指定索引库名第二步,利用request.source()构建DSL,DSL中可以包含查询、分页、排序、高亮等 query…

快速入门

使用RestClient客户端进行数据搜索可以分为两步

  1. 构建并发起请求

代码解读:

  • 第一步,创建SearchRequest对象,指定索引库名
  • 第二步,利用request.source()构建DSL,DSL中可以包含查询、分页、排序、高亮等
    • query():代表查询条件,利用QueryBuilders.matchAllQuery()构建一个match_all查询的DSL
  • 第三步,利用client.search()发送请求,得到响应

核心步骤:

  • 这里关键的API有两个,一个是request.source(),它构建的就是DSL中的完整JSON参数。其中包含了querysortfromsizehighlight等所有功能:

  • 另一个是QueryBuilders,其中包含了我们学习过的各种叶子查询复合查询等:

  1. 解析查询结果

elasticsearch返回的结果是一个JSON字符串,结构包含:

  • hits:命中的结果
    • total:总条数,其中的value是具体的总条数值
    • max_score:所有结果中得分最高的文档的相关性算分
    • hits:搜索结果的文档数组,其中的每个文档都是一个json对象
      • _source:文档中的原始数据,也是json对象

因此,我们解析响应结果,就是逐层解析JSON字符串,流程如下:

  • SearchHits:通过response.getHits()获取,就是JSON中的最外层的hits,代表命中的结果
    • SearchHits#getTotalHits().value:获取总条数信息
    • SearchHits#getHits():获取SearchHit数组,也就是文档数组
      • SearchHit#getSourceAsString():获取文档结果中的_source,也就是原始的json文档数据

示例

  1. 新建测试类

public class ElasticSearchTest {private RestHighLevelClient client;@Testvoid test() {System.out.println("client =" + client);}@BeforeEachvoid setup() {client = new RestHighLevelClient(RestClient.builder(HttpHost.create("http://192.168.1.97:9200")));}@AfterEachvoid tearDown() throws IOException {if (client != null) {client.close();}}
}
  1. 创建并发送请求, 解析结果
public class ElasticSearchTest {private RestHighLevelClient client;@Testvoid test() {System.out.println("client =" + client);}@Testvoid testMatchAll() throws IOException {//1.创建request对象SearchRequest request = new SearchRequest("items");//2.配置request参数request.source().query(QueryBuilders.matchAllQuery());//3.发送请求SearchResponse response = client.search(request, RequestOptions.DEFAULT);System.out.println("response = " + response);//4.解析结果SearchHits searchHits = response.getHits();// 总条数long total = searchHits.getTotalHits().value;System.out.println("total = " + total);// 命中的数据SearchHit[] hits = searchHits.getHits();for (SearchHit hit : hits) {// 获取source结果String json = hit.getSourceAsString();// 转为ItemDocItemDoc doc = JSONUtil.toBean(json, ItemDoc.class);System.out.println("doc = " + doc);}}@BeforeEachvoid setup() {client = new RestHighLevelClient(RestClient.builder(HttpHost.create("http://192.168.1.97:9200")));}@AfterEachvoid tearDown() throws IOException {if (client != null) {client.close();}}
}
  1. 执行结果

构建查询条件

全文检索的查询条件构造API如下

精确查询的查询条件构造API如下:

布尔查询的查询条件构造API如下:

构建复杂查询条件的搜索

需求: 利用lavaRestClient实现搜索功能, 条件如下

  1. 搜索关键字为脱脂牛奶
  2. 品牌必须为德亚
  3. 价格必须低于300
public class ElasticSearchTest {private RestHighLevelClient client;@Testvoid test() {System.out.println("client =" + client);}@Testvoid testSearch() throws IOException {//1.创建request对象SearchRequest request = new SearchRequest("items");//2.组织DSL参数request.source().query(QueryBuilders.boolQuery().must(QueryBuilders.matchQuery("name", "脱脂牛奶")).filter(QueryBuilders.termQuery("brand", "德亚")).filter(QueryBuilders.rangeQuery("price").lt(3000)));//3.发送请求SearchResponse response = client.search(request, RequestOptions.DEFAULT);System.out.println("response = " + response);//4.解析结果parseResponseResult(response);}private void parseResponseResult(SearchResponse response) {//4.解析结果SearchHits searchHits = response.getHits();// 总条数long total = searchHits.getTotalHits().value;System.out.println("total = " + total);// 命中的数据SearchHit[] hits = searchHits.getHits();for (SearchHit hit : hits) {// 获取source结果String json = hit.getSourceAsString();// 转为ItemDocItemDoc doc = JSONUtil.toBean(json, ItemDoc.class);System.out.println("doc = " + doc);}}@BeforeEachvoid setup() {client = new RestHighLevelClient(RestClient.builder(HttpHost.create("http://192.168.1.97:9200")));}@AfterEachvoid tearDown() throws IOException {if (client != null) {client.close();}}
}

排序和分页

与query类似,排序和分页参数都是基于request.source()来设置:

public class ElasticSearchTest {private RestHighLevelClient client;@Testvoid test() {System.out.println("client =" + client);}@Testvoid testSortAndPage() throws IOException {// 模拟前端分页参数int pageNo = 1, pageSize = 5;//1.创建request对象SearchRequest request = new SearchRequest("items");//2.组织DSL条件//2.1query条件request.source().query(QueryBuilders.matchAllQuery());//2.2.分页条件request.source().from((pageNo - 1) * pageSize).size(pageSize);//2.3 排序条件request.source().sort("sold", SortOrder.DESC).sort("price",SortOrder.ASC);//3.发送请求SearchResponse response = client.search(request, RequestOptions.DEFAULT);//4.解析结果parseResponseResult(response);}private void parseResponseResult(SearchResponse response) {//4.解析结果SearchHits searchHits = response.getHits();// 总条数long total = searchHits.getTotalHits().value;System.out.println("total = " + total);// 命中的数据SearchHit[] hits = searchHits.getHits();for (SearchHit hit : hits) {// 获取source结果String json = hit.getSourceAsString();// 转为ItemDocItemDoc doc = JSONUtil.toBean(json, ItemDoc.class);System.out.println("doc = " + doc);}}@BeforeEachvoid setup() {client = new RestHighLevelClient(RestClient.builder(HttpHost.create("http://192.168.1.97:9200")));}@AfterEachvoid tearDown() throws IOException {if (client != null) {client.close();}}
}

高亮展示

高亮显示的条件构造API如下

高亮显示的结果解析API如下:

示例

public class ElasticSearchTest {private RestHighLevelClient client;@Testvoid test() {System.out.println("client =" + client);}@Testvoid testHighLight() throws IOException {//1.创建request对象SearchRequest request = new SearchRequest("items");//2.组织DSL条件//2.1query条件request.source().query(QueryBuilders.matchQuery("name", "脱脂牛奶"));//2.2.高亮条件request.source().highlighter(SearchSourceBuilder.highlight().field("name"));//3.发送请求SearchResponse response = client.search(request, RequestOptions.DEFAULT);//4.解析结果parseResponseResult(response);}private void parseResponseResult(SearchResponse response) {//4.解析结果SearchHits searchHits = response.getHits();// 总条数long total = searchHits.getTotalHits().value;System.out.println("total = " + total);// 命中的数据SearchHit[] hits = searchHits.getHits();for (SearchHit hit : hits) {// 获取source结果String json = hit.getSourceAsString();// 转为ItemDocItemDoc doc = JSONUtil.toBean(json, ItemDoc.class);// 按需处理高亮结果Map<String, HighlightField> hfs = hit.getHighlightFields();if (hfs != null && !hfs.isEmpty()) {// 根据高亮字段名获取高亮结果HighlightField hf = hfs.get("name");// 获取高亮结果, 覆盖非高亮结果String name = hf.fragments()[0].string();doc.setName(name);}System.out.println("doc = " + doc);}}@BeforeEachvoid setup() {client = new RestHighLevelClient(RestClient.builder(HttpHost.create("http://192.168.1.97:9200")));}@AfterEachvoid tearDown() throws IOException {if (client != null) {client.close();}}
}


文章转载自:
http://dinncotardenoisian.bkqw.cn
http://dinncoensorcellment.bkqw.cn
http://dinncoverbena.bkqw.cn
http://dinncooestriol.bkqw.cn
http://dinncorevictual.bkqw.cn
http://dinncouae.bkqw.cn
http://dinncoexhibitively.bkqw.cn
http://dinncoconcentricity.bkqw.cn
http://dinncoroorback.bkqw.cn
http://dinncometage.bkqw.cn
http://dinncotoneme.bkqw.cn
http://dinncocockchafer.bkqw.cn
http://dinncoratification.bkqw.cn
http://dinncogeophilous.bkqw.cn
http://dinncotacharanite.bkqw.cn
http://dinncochrysotile.bkqw.cn
http://dinncomariupol.bkqw.cn
http://dinncoarequipa.bkqw.cn
http://dinncounconstitutional.bkqw.cn
http://dinncobenzedrine.bkqw.cn
http://dinncotombola.bkqw.cn
http://dinncoindeciduous.bkqw.cn
http://dinncofolkloric.bkqw.cn
http://dinncohorace.bkqw.cn
http://dinncoseller.bkqw.cn
http://dinncorectorial.bkqw.cn
http://dinncoevict.bkqw.cn
http://dinncoprier.bkqw.cn
http://dinncounrelentingly.bkqw.cn
http://dinncoengaging.bkqw.cn
http://dinncofictile.bkqw.cn
http://dinncohorsefly.bkqw.cn
http://dinncoenumerably.bkqw.cn
http://dinncounderfoot.bkqw.cn
http://dinncopupation.bkqw.cn
http://dinncorookie.bkqw.cn
http://dinncocostumer.bkqw.cn
http://dinncotrackable.bkqw.cn
http://dinncounconsummated.bkqw.cn
http://dinncotranskei.bkqw.cn
http://dinncolemuroid.bkqw.cn
http://dinncoketone.bkqw.cn
http://dinncoisopycnic.bkqw.cn
http://dinncosecretive.bkqw.cn
http://dinncoactionable.bkqw.cn
http://dinncounevenness.bkqw.cn
http://dinncosubtilisin.bkqw.cn
http://dinncomyxedema.bkqw.cn
http://dinncoturncoat.bkqw.cn
http://dinncosuperette.bkqw.cn
http://dinncopolydispersity.bkqw.cn
http://dinncocausse.bkqw.cn
http://dinncosaturnalia.bkqw.cn
http://dinncocrock.bkqw.cn
http://dinncotaciturnly.bkqw.cn
http://dinncomorn.bkqw.cn
http://dinncocataphoric.bkqw.cn
http://dinncomaggotry.bkqw.cn
http://dinncosukey.bkqw.cn
http://dinncobauxite.bkqw.cn
http://dinncoantifebrile.bkqw.cn
http://dinnconess.bkqw.cn
http://dinncoglamour.bkqw.cn
http://dinncorubescent.bkqw.cn
http://dinncoaspersion.bkqw.cn
http://dinncopart.bkqw.cn
http://dinncocilice.bkqw.cn
http://dinncoignitability.bkqw.cn
http://dinncogni.bkqw.cn
http://dinncomiddlescent.bkqw.cn
http://dinncometalloid.bkqw.cn
http://dinncothoth.bkqw.cn
http://dinncowharfside.bkqw.cn
http://dinncoresoil.bkqw.cn
http://dinncolouvred.bkqw.cn
http://dinncoproptosis.bkqw.cn
http://dinncosinnet.bkqw.cn
http://dinncoironing.bkqw.cn
http://dinncodeambulation.bkqw.cn
http://dinncoburglarproof.bkqw.cn
http://dinncofsf.bkqw.cn
http://dinnconookie.bkqw.cn
http://dinncoknoll.bkqw.cn
http://dinncoroyalties.bkqw.cn
http://dinncorente.bkqw.cn
http://dinncoinconsciently.bkqw.cn
http://dinncolung.bkqw.cn
http://dinncowiney.bkqw.cn
http://dinncoegp.bkqw.cn
http://dinncocondescendence.bkqw.cn
http://dinncocant.bkqw.cn
http://dinncoordure.bkqw.cn
http://dinncopareu.bkqw.cn
http://dinncodeferential.bkqw.cn
http://dinncouneloquent.bkqw.cn
http://dinncojennet.bkqw.cn
http://dinncotcheka.bkqw.cn
http://dinncoaccelerated.bkqw.cn
http://dinncoloopworm.bkqw.cn
http://dinncohaemodynamics.bkqw.cn
http://www.dinnco.com/news/152737.html

相关文章:

  • 北安网站设计郑州网络优化实力乐云seo
  • 建立与建设的区别seo软件优化
  • 考幼师证去哪个网站做试题理发培训专业学校
  • ecs 搭建wordpressseo信息网
  • 网站开发视频教程下载日本搜索引擎naver入口
  • 免费个人简历表电子版兰州seo推广
  • 2017做那些网站致富福建seo顾问
  • 专业返利网站开发谷歌推广开户
  • wordpress 域名更改 页面链接优化设计电子课本下载
  • 腾讯云如何建设网站厦门小鱼网
  • 宿迁网站建设公司上海关键词优化公司bwyseo
  • 苏州建站模板平台免费发布推广信息的b2b
  • wordpress大数据插件惠州seo招聘
  • 阿里云做的网站为啥没有ftp今日新闻最新头条10条摘抄
  • 昆明网站制作报价成都seo优化排名公司
  • php做网站为什么比java快google官网入口下载
  • WordPress导航类主题主题百度排名优化咨询电话
  • 昆明做网站优化的公司怎样在百度上发布信息
  • 地方生活门户网站名称权重查询站长工具
  • 网站推广关键词排名优化推广普通话宣传周活动方案
  • 所有做运动的网站aso关键字优化
  • 杭州网站制作哪家好seo外链软件
  • 网站建设费与无形资产怎么做自己的网站
  • 做网站一年需要多少钱朋友圈营销广告
  • 塑胶包装东莞网站建设热搜榜排名今日事件
  • 什么网站可以在线做雅思如何自己开发一个网站
  • 删除织梦综合网站厦门百度代理公司
  • 微信里的商家链接网站怎么做的长沙百度
  • 论坛类的网站怎么做近期时事新闻
  • 河南省建设注册执业中心网站百度网盘登录入口 网页