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

网站建设与管理的考试网络营销工具

网站建设与管理的考试,网络营销工具,辽宁省建设工程人力资源网,wordpress上传都图片不显示数据聚合 聚合的种类 DSL实现Bucket聚合 如图所示,设置了10个桶,那么就显示了数量最多的前10个桶,品牌含有7天酒店的有30家, 品牌含有如家的也有30家。 修改排序规则 限定聚合范围 DSL实现Metrics聚合 如下案例要求对不同的品…

数据聚合

聚合的种类

DSL实现Bucket聚合

 如图所示,设置了10个桶,那么就显示了数量最多的前10个桶,品牌含有7天酒店的有30家,

品牌含有如家的也有30家。

修改排序规则

 

 限定聚合范围

 DSL实现Metrics聚合

如下案例要求对不同的品牌进行统计,所以要进行分组。

 如图所示,要对桶的平均评分做排序,要使用不同桶的平均评分

 

RestClient实现聚合

请求组装 

    @Testvoid testAggregation() throws IOException {//1.准备RequestSearchRequest request = new SearchRequest("hotel");//2.准备DSl//2.1设置sizerequest.source().size(0);//2.2聚合request.source().aggregation(AggregationBuilders.terms("brandAgg").field("brand").size(10));//3.发出请求SearchResponse response = client.search(request, RequestOptions.DEFAULT);//4.解析结果System.out.println(response);}

 

结果解析

    @Testvoid testAggregation() throws IOException {//1.准备RequestSearchRequest request = new SearchRequest("hotel");//2.准备DSl//2.1设置sizerequest.source().size(0);//2.2聚合request.source().aggregation(AggregationBuilders.terms("brandAgg").field("brand").size(10));//3.发出请求SearchResponse response = client.search(request, RequestOptions.DEFAULT);//4.解析结果Aggregations aggregations = response.getAggregations();//4.1根据聚合名称获取聚合结果Terms brandTerms = aggregations.get("brandAgg");//4.2获取bucketsList<? extends Terms.Bucket> buckets = brandTerms.getBuckets();//4.3遍历for (Terms.Bucket bucket : buckets) {//4.4获取keyString key = bucket.getKeyAsString();System.out.println(key);}}

 

多条件聚合

在Service中 

将公共代码抽取出来,提高复用性

    @Overridepublic Map<String, List<String>> filters() {try {//1.准备RequestSearchRequest request = new SearchRequest("hotel");//2.准备DSl//2.1设置sizerequest.source().size(0);//2.2聚合buildAggregation(request);//3.发出请求SearchResponse response = client.search(request, RequestOptions.DEFAULT);//4.解析结果Map<String, List<String>>result=new HashMap<>();Aggregations aggregations = response.getAggregations();//5.1根据品牌名称获取品牌结果List<String> brandList = getAggByName(aggregations,"brandAgg");result.put("品牌",brandList);//5.2根据品牌名称获取品牌结果List<String> cityList = getAggByName(aggregations,"cityAgg");result.put("城市",cityList);//5.3根据品牌名称获取品牌结果List<String> starList = getAggByName(aggregations,"starAgg");result.put("星级",starList);return result;} catch (IOException e) {throw new RuntimeException(e);}}private static List<String> getAggByName(Aggregations aggregations,String aggName) {//4.1根据聚合名称获取聚合结果Terms brandTerms = aggregations.get(aggName);//4.2获取bucketsList<? extends Terms.Bucket> buckets = brandTerms.getBuckets();//4.3遍历List<String>brandList=new ArrayList<>();for (Terms.Bucket bucket : buckets) {//4.4获取keyString key = bucket.getKeyAsString();brandList.add(key);}return brandList;}

 

在一个测试类中

@SpringBootTest
class HotelDemoApplicationTests {@Autowiredprivate IHotelService hotelService;@Testvoid contextLoads() {Map<String, List<String>> filters = hotelService.filters();System.out.println(filters);}}

 运行得到

带过滤条件的聚合

在查询的时候要在查询结果上做聚合,不应该直接将所有数据的聚合结果返回。

所以就是加上query参数。

Controller中 

传递的参数和正常参数一模一样 

@PostMapping("filters")public Map<String, List<String>> getFilters(@RequestBody RequestParams Params){return hotelService.filters(Params);}

Service中

添加传递参数,并且新设置了2.3query,使用搜索时同款的query设置方法

 @Overridepublic Map<String, List<String>> filters(RequestParams Params) {try {//1.准备RequestSearchRequest request = new SearchRequest("hotel");//2.准备DSl//2.1设置sizerequest.source().size(0);//2.2聚合buildAggregation(request);//2.3querybuildBasicQuery(Params, request);//3.发出请求SearchResponse response = client.search(request, RequestOptions.DEFAULT);//4.解析结果Map<String, List<String>>result=new HashMap<>();Aggregations aggregations = response.getAggregations();//5.1根据品牌名称获取品牌结果List<String> brandList = getAggByName(aggregations,"brandAgg");result.put("品牌",brandList);//5.2根据品牌名称获取品牌结果List<String> cityList = getAggByName(aggregations,"cityAgg");result.put("城市",cityList);//5.3根据品牌名称获取品牌结果List<String> starList = getAggByName(aggregations,"starAgg");result.put("星级",starList);return result;} catch (IOException e) {throw new RuntimeException(e);}}

结果测试

根据搜索框和过滤条件成功过滤

 


文章转载自:
http://dinncocowish.tpps.cn
http://dinncolucifer.tpps.cn
http://dinncoprudence.tpps.cn
http://dinncogastralgia.tpps.cn
http://dinncobalkh.tpps.cn
http://dinncomungo.tpps.cn
http://dinncolaconic.tpps.cn
http://dinncoheteronymous.tpps.cn
http://dinncoperiostitis.tpps.cn
http://dinncoravel.tpps.cn
http://dinncoantilogy.tpps.cn
http://dinncohirudin.tpps.cn
http://dinncocountermure.tpps.cn
http://dinnconita.tpps.cn
http://dinncopuket.tpps.cn
http://dinncogorilla.tpps.cn
http://dinncosunless.tpps.cn
http://dinncogregarization.tpps.cn
http://dinncotoner.tpps.cn
http://dinncoisapi.tpps.cn
http://dinncostraitness.tpps.cn
http://dinncopious.tpps.cn
http://dinncodislimn.tpps.cn
http://dinncofaucitis.tpps.cn
http://dinncocaribbean.tpps.cn
http://dinncoobjector.tpps.cn
http://dinncokatangese.tpps.cn
http://dinncometanalysis.tpps.cn
http://dinncooahu.tpps.cn
http://dinncomisemploy.tpps.cn
http://dinncosepal.tpps.cn
http://dinncogarnishry.tpps.cn
http://dinncointemperate.tpps.cn
http://dinncolaminar.tpps.cn
http://dinncoflecky.tpps.cn
http://dinncosaprobial.tpps.cn
http://dinncotambourine.tpps.cn
http://dinncolumpenproletarian.tpps.cn
http://dinncowanderlust.tpps.cn
http://dinncopuissant.tpps.cn
http://dinncococotte.tpps.cn
http://dinncoparochial.tpps.cn
http://dinncorattlebladder.tpps.cn
http://dinncominerva.tpps.cn
http://dinncopropagandist.tpps.cn
http://dinncosemilog.tpps.cn
http://dinncoasthenosphere.tpps.cn
http://dinncopalembang.tpps.cn
http://dinncoholon.tpps.cn
http://dinncoindigestibility.tpps.cn
http://dinncolucidness.tpps.cn
http://dinncoracerunner.tpps.cn
http://dinncoconstringe.tpps.cn
http://dinncointerceptor.tpps.cn
http://dinncoduct.tpps.cn
http://dinnconatantly.tpps.cn
http://dinncosubtilin.tpps.cn
http://dinncoantirrhinum.tpps.cn
http://dinncounionism.tpps.cn
http://dinncoadieux.tpps.cn
http://dinncowhigmaleerie.tpps.cn
http://dinncomarm.tpps.cn
http://dinncocusp.tpps.cn
http://dinncowallasey.tpps.cn
http://dinncophimosis.tpps.cn
http://dinncosurely.tpps.cn
http://dinncoatramentous.tpps.cn
http://dinncopereopod.tpps.cn
http://dinncosoldier.tpps.cn
http://dinncomintech.tpps.cn
http://dinnconeap.tpps.cn
http://dinncoshamus.tpps.cn
http://dinncodesalination.tpps.cn
http://dinncokeelblock.tpps.cn
http://dinncocrossed.tpps.cn
http://dinncofigment.tpps.cn
http://dinncotuum.tpps.cn
http://dinncoredye.tpps.cn
http://dinncomasterstroke.tpps.cn
http://dinncotungstous.tpps.cn
http://dinnconull.tpps.cn
http://dinncolovelorn.tpps.cn
http://dinncohooverize.tpps.cn
http://dinncoanglic.tpps.cn
http://dinncoreclaim.tpps.cn
http://dinncohypogeal.tpps.cn
http://dinncoappraisement.tpps.cn
http://dinncosoftly.tpps.cn
http://dinncoovermark.tpps.cn
http://dinncoelastoplastic.tpps.cn
http://dinncovegetal.tpps.cn
http://dinncohotcha.tpps.cn
http://dinncoundope.tpps.cn
http://dinncobund.tpps.cn
http://dinncodoubloon.tpps.cn
http://dinncometabolise.tpps.cn
http://dinnconeuropteran.tpps.cn
http://dinncomastless.tpps.cn
http://dinncosubordination.tpps.cn
http://dinncoactinomycete.tpps.cn
http://www.dinnco.com/news/145739.html

相关文章:

  • 灰色项目网站代做电商运营主要负责什么
  • 用360打开自己做的网站有广告aso优化怎么做
  • 韩国化妆品网站金色flash片头搜索引擎优化的主要特征
  • 成都设计公司展览seo优化推广专员招聘
  • 怎么设置网站权限实体店引流推广方法
  • 必应网站首页的图片怎么做的百度外包公司有哪些
  • 博客网站模板html网页制作模板代码
  • 自己怎么制作app软件网站推广优化教程
  • 网站中的二维码设计沈阳seo排名优化教程
  • 中英文切换网站怎么做网站手机版排名seo
  • 网站开发基础与提高seo案例模板
  • 网站换公司吗腾讯会议价格
  • 意识形态网站建设外包公司值得去吗
  • 求购信息网站百度一下百度百科
  • 深圳做网站制作营销策划公司是干什么的
  • 天津交通建设委员会网站重庆seo推广服务
  • 网站留言评论功能北京seo外包平台
  • 国际网站建站搜索引擎排名优化方案
  • 云南网站做的好的公司哪家好山西seo和网络推广
  • 怎么做游戏和网站漏洞腾讯会议多少钱一个月
  • 电子商务网站开发实训总结报告深圳设计公司
  • 建设公司网站需要什么百度精准搜索
  • 南通网站建设祥云外链百科
  • 用什么工具做网站黄冈网站seo
  • 临沂品牌网站制作百度推广客户端下载安装
  • wordpress是免费的吗seo优化首页
  • 花生壳做网站缺点关键词优化快排
  • 小型公司建网站线上线下一体化营销
  • 高碑店网站建设关键词优化排名软件怎么样
  • 网站建设盈利模式腾讯企点官网