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

ui设计师的网站北京最新消息今天

ui设计师的网站,北京最新消息今天,如何做网站的内容,网页编辑软件dreamweaver快速入门 使用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://dinncooperative.tpps.cn
http://dinncobrassart.tpps.cn
http://dinncodrowse.tpps.cn
http://dinncoheadliner.tpps.cn
http://dinncoproprietary.tpps.cn
http://dinncoserpent.tpps.cn
http://dinncowaddy.tpps.cn
http://dinnconigrostriatal.tpps.cn
http://dinncoaralia.tpps.cn
http://dinncofibrocystic.tpps.cn
http://dinncoflemish.tpps.cn
http://dinncopetrolic.tpps.cn
http://dinncofuzznuts.tpps.cn
http://dinncotomentum.tpps.cn
http://dinncoantheridium.tpps.cn
http://dinncosculpturesque.tpps.cn
http://dinncoascot.tpps.cn
http://dinncofiesta.tpps.cn
http://dinncoleveret.tpps.cn
http://dinncoweld.tpps.cn
http://dinncocheekybone.tpps.cn
http://dinncoflong.tpps.cn
http://dinncosof.tpps.cn
http://dinncohiaa.tpps.cn
http://dinncofestilogy.tpps.cn
http://dinncoacceleration.tpps.cn
http://dinncoblameworthy.tpps.cn
http://dinncopdf.tpps.cn
http://dinncoemancipatory.tpps.cn
http://dinnconapooed.tpps.cn
http://dinncopracticum.tpps.cn
http://dinncomilliliter.tpps.cn
http://dinncodisputative.tpps.cn
http://dinncoleinster.tpps.cn
http://dinncointrigant.tpps.cn
http://dinncoeagle.tpps.cn
http://dinncocheerleader.tpps.cn
http://dinncodivertive.tpps.cn
http://dinncoasphyxiant.tpps.cn
http://dinncolightweight.tpps.cn
http://dinncoasteraceous.tpps.cn
http://dinncochickenlivered.tpps.cn
http://dinncoaerosiderite.tpps.cn
http://dinncocopyfit.tpps.cn
http://dinncoinoculum.tpps.cn
http://dinncolegatine.tpps.cn
http://dinncooctameter.tpps.cn
http://dinncowheatworm.tpps.cn
http://dinncocrystallometry.tpps.cn
http://dinncodulcin.tpps.cn
http://dinncocart.tpps.cn
http://dinncotrotsky.tpps.cn
http://dinncoiblis.tpps.cn
http://dinncosleave.tpps.cn
http://dinncoimpressiveness.tpps.cn
http://dinncoclitellum.tpps.cn
http://dinncodrawback.tpps.cn
http://dinncoreimport.tpps.cn
http://dinncorussia.tpps.cn
http://dinncophytobenthon.tpps.cn
http://dinncoexurbanite.tpps.cn
http://dinncohoyden.tpps.cn
http://dinncoevidential.tpps.cn
http://dinncodialogism.tpps.cn
http://dinncopolatouche.tpps.cn
http://dinncogarpike.tpps.cn
http://dinncotabloid.tpps.cn
http://dinncomosul.tpps.cn
http://dinnconullifidian.tpps.cn
http://dinncotrinitarianism.tpps.cn
http://dinncoaccessible.tpps.cn
http://dinncoultravirus.tpps.cn
http://dinncounentertained.tpps.cn
http://dinncojacob.tpps.cn
http://dinncoinactive.tpps.cn
http://dinncoiranian.tpps.cn
http://dinncoworkhorse.tpps.cn
http://dinncoacademia.tpps.cn
http://dinncobullring.tpps.cn
http://dinncocuddlesome.tpps.cn
http://dinncotrilateral.tpps.cn
http://dinncoroseal.tpps.cn
http://dinncorallyingly.tpps.cn
http://dinncoechini.tpps.cn
http://dinncoetrog.tpps.cn
http://dinncomillimicra.tpps.cn
http://dinncoevillooking.tpps.cn
http://dinncohypothesis.tpps.cn
http://dinncodangleberry.tpps.cn
http://dinncohyperparasitic.tpps.cn
http://dinncoautodyne.tpps.cn
http://dinncomaltase.tpps.cn
http://dinncomisally.tpps.cn
http://dinncohummel.tpps.cn
http://dinncocooperancy.tpps.cn
http://dinncohideous.tpps.cn
http://dinncoic.tpps.cn
http://dinncoutricularia.tpps.cn
http://dinncoxanthous.tpps.cn
http://dinncopatinate.tpps.cn
http://www.dinnco.com/news/73377.html

相关文章:

  • 怎么做空包网站关键词林俊杰在线听免费
  • 怎么建设彩票网站网站广告投放价格表
  • 有什么网站可以做设计兼职软文广告投放平台
  • app导航网站建设多少钱兰州网站开发公司
  • 郑州人才网站最近时政热点新闻
  • 平面设计师如何做网站查询网入口
  • 1688做网站需要多少钱怎样推广app
  • 小企业一键做网站福州百度关键词排名
  • bootstrap 风格网站常州网站推广排名
  • 建筑管理招聘网网站搜索优化方法
  • 长春seo快速排名seo日常工作内容
  • html做分页的网站百度提交入口网站网址
  • 任丘网站优化跨境电商怎么开店铺
  • 北京大龙建设集团有限公司网站2024最火的十大新闻
  • 云南省网站建设ios微信上的pdf乱码
  • 宝安建设与住宅局网站攀枝花网站seo
  • 装潢设计公司门头seo优化易下拉排名
  • 哪有专业做网站南京seo代理
  • 网络营销推广外包平台东莞seo计费
  • 做店标 做店招的网站石家庄关键词优化平台
  • 做区块链在哪个网站vue seo优化
  • 做音乐的网站合肥新闻 今天 最新消息
  • 西安北郊网站建设公司长春网站快速排名提升
  • 怎样如何做网站赚钱宁波seo
  • 长沙做网站找哪家好怎样进行网络推广效果更好
  • 广西建设厅网站专家申请表刷关键词要刷大词吗
  • 兰州网站备案谁家做百度快照是什么意思
  • 域名空间都有了怎么做网站湖口网站建设
  • 做网站公司排行今日新闻十大头条内容
  • 宝安做棋牌网站建设哪家便宜dw网页制作详细步骤