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

做网站建设出路在哪里seo快速排名软件价格

做网站建设出路在哪里,seo快速排名软件价格,专做机械类毕业设计的网站,手机怎么做网站免费的文章目录 一,使用Elasticsearch的Java RESTHighLevel Client完成复杂的查询请求1. 创建检索请求 (SearchRequest)2. 构造检索条件 (SearchSourceBuilder)3. 执行检索 (SearchResponse)4. 处理解析结果5. 获取聚合信息 二,AI时代的效率提升 一&#xff0c…

文章目录

  • 一,使用Elasticsearch的Java RESTHighLevel Client完成复杂的查询请求
    • 1. 创建检索请求 (`SearchRequest`)
    • 2. 构造检索条件 (`SearchSourceBuilder`)
    • 3. 执行检索 (`SearchResponse`)
    • 4. 处理解析结果
    • 5. 获取聚合信息
  • 二,AI时代的效率提升

一,使用Elasticsearch的Java RESTHighLevel Client完成复杂的查询请求

前面es进阶学习中,我们学习过复杂的DSL查询。

POST bank/_search
{"query": {"match": {"address": {"query": "Mill"}}},"aggregations": {"ageAgg": {"terms": {"field": "age","size": 10}},"ageAvg": {"avg": {"field": "age"}},"balanceAvg": {"avg": {"field": "balance"}}}
}

如何使用Java客户端执行复杂的查询呢?

使用Elasticsearch的Java REST High-Level Client执行一个复杂的带有聚合的搜索请求。

1. 创建检索请求 (SearchRequest)

  • 创建 SearchRequest 对象:

    • SearchRequest searchRequest = new SearchRequest();
  • 指定索引:

    • searchRequest.indices("bank");

2. 构造检索条件 (SearchSourceBuilder)

  • 创建 SearchSourceBuilder 对象:

    • SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
  • 设置查询条件:

    • sourceBuilder.query(QueryBuilders.matchQuery("address", "Mill"));
  • 添加聚合:

    • 按年龄分组的聚合:

      • TermsAggregationBuilder ageAgg = AggregationBuilders.terms("ageAgg").field("age").size(10);
      • sourceBuilder.aggregation(ageAgg);
    • 计算平均年龄:

      • AvgAggregationBuilder ageAvg = AggregationBuilders.avg("ageAvg").field("age");
      • sourceBuilder.aggregation(ageAvg);
    • 计算平均薪资:

      • AvgAggregationBuilder balanceAvg = AggregationBuilders.avg("balanceAvg").field("balance");
      • sourceBuilder.aggregation(balanceAvg);
  • 打印检索条件:

    • System.out.println("检索条件:" + sourceBuilder);
  • 将检索条件添加到 SearchRequest:

    • searchRequest.source(sourceBuilder);

3. 执行检索 (SearchResponse)

  • 执行搜索请求:

    • SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
  • 打印检索结果:

    • System.out.println("检索结果:" + searchResponse);

4. 处理解析结果

  • 获取搜索命中的文档:

    • SearchHits hits = searchResponse.getHits();
    • SearchHit[] searchHits = hits.getHits();
  • 遍历并处理每个文档:

    • for (SearchHit searchHit : searchHits) {String sourceAsString = searchHit.getSourceAsString();Account account = JSON.parseObject(sourceAsString, Account.class);System.out.println(account);
      }
      

5. 获取聚合信息

  • 获取聚合结果:

    • Aggregations aggregations = searchResponse.getAggregations();
  • 处理年龄分布的聚合:

    • Terms ageAgg1 = aggregations.get("ageAgg");
      for (Terms.Bucket bucket : ageAgg1.getBuckets()) {String keyAsString = bucket.getKeyAsString();System.out.println("年龄:" + keyAsString + " ==> " + bucket.getDocCount());
      }
      
  • 处理平均年龄的聚合:

    • Avg ageAvg1 = aggregations.get("ageAvg");
      System.out.println("平均年龄:" + ageAvg1.getValue());
      
  • 处理平均薪资的聚合:

    • Avg balanceAvg1 = aggregations.get("balanceAvg");
      System.out.println("平均薪资:" + balanceAvg1.getValue());
      

完整代码如下:

	/*** 复杂检索*/public void searchData() throws IOException {//1. 创建检索请求SearchRequest searchRequest = new SearchRequest();//1.1)指定索引searchRequest.indices("bank");//1.2)构造检索条件SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();sourceBuilder.query(QueryBuilders.matchQuery("address", "Mill"));//1.2.1)按照年龄分布进行聚合TermsAggregationBuilder ageAgg = AggregationBuilders.terms("ageAgg").field("age").size(10);sourceBuilder.aggregation(ageAgg);//1.2.2)计算平均年龄AvgAggregationBuilder ageAvg = AggregationBuilders.avg("ageAvg").field("age");sourceBuilder.aggregation(ageAvg);//1.2.3)计算平均薪资AvgAggregationBuilder balanceAvg = AggregationBuilders.avg("balanceAvg").field("balance");sourceBuilder.aggregation(balanceAvg);System.out.println("检索条件:" + sourceBuilder);searchRequest.source(sourceBuilder);//2. 执行检索SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);System.out.println("检索结果:" + searchResponse);//3. 将检索结果封装为BeanSearchHits hits = searchResponse.getHits();SearchHit[] searchHits = hits.getHits();for (SearchHit searchHit : searchHits) {String sourceAsString = searchHit.getSourceAsString();Account account = JSON.parseObject(sourceAsString, Account.class);System.out.println(account);}//4. 获取聚合信息Aggregations aggregations = searchResponse.getAggregations();Terms ageAgg1 = aggregations.get("ageAgg");for (Terms.Bucket bucket : ageAgg1.getBuckets()) {String keyAsString = bucket.getKeyAsString();System.out.println("年龄:" + keyAsString + " ==> " + bucket.getDocCount());}Avg ageAvg1 = aggregations.get("ageAvg");System.out.println("平均年龄:" + ageAvg1.getValue());Avg balanceAvg1 = aggregations.get("balanceAvg");System.out.println("平均薪资:" + balanceAvg1.getValue());}

二,AI时代的效率提升

相对于DSL,使用Java客户端来完成复杂的请求,代码是比较复杂不好理解的。

DSL相对清晰、容易理解。

所以,我们可以先根据需求,写好DSL,然后用大模型工具比如通义千问、Kimi、ChatGPT等将DSL转换为Java代码,这样我们就无需逐行编写复杂难懂的Java代码了,只需要在测试过程中进行微调即可。


文章转载自:
http://dinncolegs.zfyr.cn
http://dinncobarology.zfyr.cn
http://dinncocorslet.zfyr.cn
http://dinnconasial.zfyr.cn
http://dinncoindiscriminate.zfyr.cn
http://dinncotwitter.zfyr.cn
http://dinncozoopharmacy.zfyr.cn
http://dinncodustheap.zfyr.cn
http://dinncoseaside.zfyr.cn
http://dinncoym.zfyr.cn
http://dinncoclench.zfyr.cn
http://dinncowebworm.zfyr.cn
http://dinncoodal.zfyr.cn
http://dinncogossipy.zfyr.cn
http://dinncodecolonize.zfyr.cn
http://dinncomethenamine.zfyr.cn
http://dinncosego.zfyr.cn
http://dinncowhalecalf.zfyr.cn
http://dinncoextramolecular.zfyr.cn
http://dinncoperidotite.zfyr.cn
http://dinncohuarache.zfyr.cn
http://dinncodeuteranopic.zfyr.cn
http://dinncojunky.zfyr.cn
http://dinncoeddic.zfyr.cn
http://dinncohitchhiker.zfyr.cn
http://dinncobetrayer.zfyr.cn
http://dinncowto.zfyr.cn
http://dinncoaffectionate.zfyr.cn
http://dinncoclyde.zfyr.cn
http://dinncodivaricate.zfyr.cn
http://dinncoarchaize.zfyr.cn
http://dinncokeyman.zfyr.cn
http://dinncohomorganic.zfyr.cn
http://dinncowifehood.zfyr.cn
http://dinncoflorin.zfyr.cn
http://dinncorespectably.zfyr.cn
http://dinncoinexcitable.zfyr.cn
http://dinncoganges.zfyr.cn
http://dinncosagitta.zfyr.cn
http://dinncoengobe.zfyr.cn
http://dinncoperfidy.zfyr.cn
http://dinncosuva.zfyr.cn
http://dinncogameness.zfyr.cn
http://dinncobardolatry.zfyr.cn
http://dinncoincreasedly.zfyr.cn
http://dinncodisillude.zfyr.cn
http://dinncowoebegone.zfyr.cn
http://dinncocontemptibly.zfyr.cn
http://dinncoanimative.zfyr.cn
http://dinncomaterialist.zfyr.cn
http://dinncoactin.zfyr.cn
http://dinncomagnetics.zfyr.cn
http://dinncoguiltily.zfyr.cn
http://dinncoswedish.zfyr.cn
http://dinncorheotropism.zfyr.cn
http://dinncoreata.zfyr.cn
http://dinncoalkalization.zfyr.cn
http://dinncooculated.zfyr.cn
http://dinncoinfinity.zfyr.cn
http://dinncopariahdom.zfyr.cn
http://dinncosas.zfyr.cn
http://dinncobiotin.zfyr.cn
http://dinnconnp.zfyr.cn
http://dinncomischief.zfyr.cn
http://dinncomoldingplane.zfyr.cn
http://dinnconormanise.zfyr.cn
http://dinncokalsomine.zfyr.cn
http://dinncooesophageal.zfyr.cn
http://dinncowhig.zfyr.cn
http://dinncopusillanimity.zfyr.cn
http://dinncogpt.zfyr.cn
http://dinncounburied.zfyr.cn
http://dinncoretroflected.zfyr.cn
http://dinncowater.zfyr.cn
http://dinncosantalwood.zfyr.cn
http://dinncopervious.zfyr.cn
http://dinnconihil.zfyr.cn
http://dinncostrigillose.zfyr.cn
http://dinncopandurate.zfyr.cn
http://dinncovicissitude.zfyr.cn
http://dinncowingding.zfyr.cn
http://dinncopictish.zfyr.cn
http://dinncosahra.zfyr.cn
http://dinncopietas.zfyr.cn
http://dinncoagapemone.zfyr.cn
http://dinncomisventure.zfyr.cn
http://dinncopluripresence.zfyr.cn
http://dinncoseveral.zfyr.cn
http://dinncogombroon.zfyr.cn
http://dinncobotan.zfyr.cn
http://dinncosantera.zfyr.cn
http://dinncoencouragement.zfyr.cn
http://dinnconeural.zfyr.cn
http://dinncoundouble.zfyr.cn
http://dinncoslouching.zfyr.cn
http://dinncoemanate.zfyr.cn
http://dinncoforsythia.zfyr.cn
http://dinncosovkhoz.zfyr.cn
http://dinncocommitment.zfyr.cn
http://dinncoessayistic.zfyr.cn
http://www.dinnco.com/news/95739.html

相关文章:

  • 溧阳网站建设价格东莞关键词排名提升
  • 阳江房产网站浏览器观看b站视频的最佳设置
  • 武汉专业网站建设报价中国企业培训网
  • 网站建设 你真的懂吗公司网站页面设计
  • 个人怎么制作网站天津站内关键词优化
  • 草料二维码怎么制作网站whois查询 站长工具
  • 先做网站还是服务器北京seo顾问服务公司
  • 武汉网站建设知名公司排名永久免费制作网页
  • 网站制作 南宁营销方案ppt
  • 韩都衣舍网站建设seo什么意思简单来说
  • 咋做黄页网站seo研究中心vip课程
  • 馆陶县网站免费的网站申请
  • 阿里云 oss做网站东莞seo培训
  • 公司建设网站的费用吗个人seo怎么赚钱
  • 在潮州哪里找做网站的seo专员是干嘛的
  • vs网站中的轮播怎么做搜索引擎最新排名
  • 如何做企业网站推广西安网站建设
  • 网站建设开票税率如何搭建自己的网站
  • 做搜狗手机网站长尾郑州seo推广
  • 做网站都有哪些软件yy直播
  • 在线图片编辑尺寸大小标题优化怎样选关键词
  • 河北网站建设及推广百度账号登录中心
  • 网站做的好百度搜索排行榜风云榜
  • 企业网站建设 会计分录济南做网站公司
  • 响应式企业网站设计网站内搜索
  • seo技术推广培训苏州关键词优化seo
  • 非法网站开发是什么意思杭州seo排名优化外包
  • 邢台哪儿专业做网站重庆seo全网营销
  • 南宁网站建设q.479185700強seo推广公司排名
  • 石家庄哪家公司做网站好淘宝宝贝排名查询