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

深圳公司有哪些优化

深圳公司有哪些,优化,网站出错咨询电话,制作网站难不难ElasticSearch系列整体栏目 内容链接地址【一】ElasticSearch下载和安装https://zhenghuisheng.blog.csdn.net/article/details/129260827【二】ElasticSearch概念和基本操作https://blog.csdn.net/zhenghuishengq/article/details/134121631【三】ElasticSearch的高级查询Quer…ElasticSearch系列整体栏目 内容链接地址【一】ElasticSearch下载和安装https://zhenghuisheng.blog.csdn.net/article/details/129260827【二】ElasticSearch概念和基本操作https://blog.csdn.net/zhenghuishengq/article/details/134121631【三】ElasticSearch的高级查询Query DSLhttps://blog.csdn.net/zhenghuishengq/article/details/134159587【四】ElasticSearch的聚合查询操作https://blog.csdn.net/zhenghuishengq/article/details/134159587【五】SpringBoot整合elasticSearchhttps://blog.csdn.net/zhenghuishengq/article/details/134212200 SpringBoot整合elasticSearch 一SpringBoot整合ElasticSearch1需要的依赖以及版本2创建config配置类并测试连接3增删改查测试3.1索引插入数据3.2根据id查询数据3.3删除一条数据 4普通查询4.1match条件查询4.2term精确匹配4.3prefix前缀查询4.4通配符查询wildcard4.5范围查询4.6fuzzy模糊查询4.7highlight高亮查询 5聚合查询5.1aggs聚合查询5.2获取最终结果 一SpringBoot整合ElasticSearch 前面几篇讲解了es的安装dsl语法聚合查询等接下来这篇主要就是讲解通过java的方式来操作es这里选择通过springboot的方式整合ElasticSearchSearch 在学习这个整合之前可以查看对应的官网资料https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/7.17/connecting.html 1需要的依赖以及版本 首先创建springboot项目然后需要的依赖如下我前面用的是7.7.0的版本因此这里继续使用这个版本。其他的依赖根据个人需要选择 propertiesjava.version8/java.versionelasticsearch.version7.7.0/elasticsearch.version /properties dependenciesdependencygroupIdorg.elasticsearch.client/groupIdartifactIdelasticsearch-rest-high-level-client/artifactIdversion7.7.0/version/dependency /dependencies2创建config配置类并测试连接 随后创建一个config的配置类用于连接上ElasticSearch我这边是单机版并没有集群 /*** 连接es的工具类*/ Configuration public class ElasticSearchConfig { public static final RequestOptions COMMON_OPTIONS;static {RequestOptions.Builder builder RequestOptions.DEFAULT.toBuilder();COMMON_OPTIONS builder.build();}Beanpublic RestHighLevelClient esRestClient(){RestHighLevelClient client new RestHighLevelClient(RestClient.builder(new HttpHost(xx.xx.xx.xx, 9200, http)));return client;} }在创建好了之后可以直接在test类中进行测试看能否连接成功 RunWith(SpringRunner.class) SpringBootTest public class StudyApplicationTests {Resourceprivate RestHighLevelClient client;Testpublic void contextLoads() {System.out.println(restHighLevelClient);} }在运行之后如果打印出了以下这句话表示整合成功 org.elasticsearch.client.RestHighLevelClient7d151a3增删改查测试 3.1索引插入数据 首先先创建一个users的索引并向里面插入一条数据。插入和更新都可以用这个方法 //创建一个user索引并且插入一条数据 Test public void addData() throws IOException {//创建一个索引IndexRequest userIndex new IndexRequest(users);User user new User();user.setId(1);user.setUsername(Tom);user.setPassword(123456);user.setAge(18);user.setSex(女);//添加数据userIndex.source(JSON.toJSONString(user), XContentType.JSON);IndexResponse response client.index(userIndex, ElasticSearchConfig.COMMON_OPTIONS);//响应数据System.out.println(response); }随后再在kibana中查询这个索引可以看到这条数据是已经插入成功的并且索引页创建成功 3.2根据id查询数据 查询id为1的数据需要通过QueryBuild构造器查询 Test public void getById() throws IOException {SearchRequest request new SearchRequest(users);SearchSourceBuilder builder new SearchSourceBuilder();builder.query(QueryBuilders.matchQuery(id, 1));request.source(builder);SearchResponse response client.search(request, RequestOptions.DEFAULT);System.out.println(response); }3.3删除一条数据 删除刚刚创建的这条数据这里直接设置id为1即可 Test public void deleteById() throws Exception{DeleteRequest request new DeleteRequest(users);request.id(1);DeleteResponse delete client.delete(request, ElasticSearchConfig.COMMON_OPTIONS);System.out.println(delete); }4普通查询 这里主要是结合本人写的第三篇Query DSL的语法通过java的方式写出依旧是先创建一个员工的信息索引并且设置字段得我属性 PUT /employees {mappings: {properties: {name:{type: keyword},job:{type: keyword},salary:{type: integer}}} }随后批量的插入10条数据 PUT /employees/_bulk { index : { _id : 1 } } { name : huisheng1,job:python,salary:35000 } { index : { _id : 2 } } { name : huisheng2,job:java,salary: 50000} { index : { _id : 3 } } { name : huisheng3,job:python,salary:18000 } { index : { _id : 4 } } { name : huisheng4,job:java,salary: 22000} { index : { _id : 5 } } { name : huisheng5,job:javascript,salary:18000 } { index : { _id : 6 } } { name : huisheng6,job:javascript,salary: 25000} { index : { _id : 7 } } { name : huisheng7,job:c,salary:20000 } { index : { _id : 8 } } { name : huisheng8,job:c,salary: 20000} { index : { _id : 9 } } { name : huisheng9,job:java,salary:22000 } { index : { _id : 10 } } { name : huisheng10,job:java,salary: 9000}4.1match条件查询 首先是分页查询分页查询的queryDSL的语法如下 GET /employees/_search {query: {match: {job: java}} }java的语法如下 SearchRequest request new SearchRequest(employees); SearchSourceBuilder builder new SearchSourceBuilder(); builder.query(QueryBuilders.matchQuery(job, java)); request.source(builder); SearchResponse response client.search(request, RequestOptions.DEFAULT); System.out.println(response);短语匹配的语法如下 builder.query(QueryBuilders.matchPhraseQuery(job,java));多字段查询的语法如下 String fields[] {job,name}; builder.query(QueryBuilders.multiMatchQuery(java,fields));queryString的语法如下 builder.query(QueryBuilders.queryStringQuery(java));4.2term精确匹配 GET /employees/_search {query: {term: {job: java}} }精确匹配通过java的方式如下 builder.query(QueryBuilders.termQuery(job,java));4.3prefix前缀查询 PUT /employees/_search {query:{prefix:{name:{value:huisheng1}}} }前缀查询的java方式如下 builder.query(QueryBuilders.prefixQuery(name,huisheng1));4.4通配符查询wildcard GET /employees/_search {query: {wildcard: {job: {value: *py*}}} }通配符查询的java方式如下 builder.query(QueryBuilders.wildcardQuery(job,py));4.5范围查询 POST /employees/_search {query: {range: {salary: {gte: 25000}}} }范围查询的java方式如下 builder.query(QueryBuilders.rangeQuery(salary).gte(25000));4.6fuzzy模糊查询 GET /employees/_search {query: {fuzzy: {job: {value: javb,fuzziness: 1 //表示允许错一个字}}} }模糊查询的java方式如下 builder.query(QueryBuilders.fuzzyQuery(job,javb).fuzziness(Fuzziness.ONE));4.7highlight高亮查询 GET /employees/_search {query: {term: {job: {value: java}}},highlight: {fields: {*:{}}} }高亮查询的java方式如下 builder.query(QueryBuilders.termQuery(job,java)); HighlightBuilder highlightBuilder new HighlightBuilder(); highlightBuilder.field(job); builder.highlighter(highlightBuilder);5聚合查询 5.1aggs聚合查询 先通过job进行分组查询再拿到结果后再进行stats查询求最大值最小值平均值等 POST /employees/_search {size: 0,aggs: {name: {terms: {field: job},aggs: {stats_salary: {stats: {field: salary}}}}} }其java代码如下需要注意的点就是如果存在二级聚合那么需要调用这个 subAggregation 方法如果只需要聚合的结果而不需要查询的结果可以直接在SearchSourceBuilder的实例设置为0即可。 Test public void toAgg() throws Exception{//创建检索请求SearchRequest searchRequest new SearchRequest();//指定索引searchRequest.indices(employees);//构建检索条件SearchSourceBuilder builder new SearchSourceBuilder();//构建聚合条件TermsAggregationBuilder aggregationBuilder AggregationBuilders.terms(jobData).field(job);aggregationBuilder.subAggregation(AggregationBuilders.stats(salaryData).field(salary));//将聚合条件加入到检索条件中builder.aggregation(aggregationBuilder);//只要聚合的结果不需要查询的结果builder.size(0);searchRequest.source(builder);//执行检索SearchResponse searchResponse client.search(searchRequest, RequestOptions.DEFAULT);System.out.println(检索结果 searchResponse); }打印的结果如下和预期要打印的结果是一致的 {took:4,timed_out:false,_shards:{total:1,successful:1,skipped:0,failed:0},hits:{total:{value:10,relation:eq},max_score:null,hits:[]},aggregations:{sterms#jobData:{doc_count_error_upper_bound:0,sum_other_doc_count:0,buckets:[{key:java,doc_count:4,stats#salaryData:{count:4,min:9000.0,max:50000.0,avg:25750.0,sum:103000.0}},{key:c,doc_count:2,stats#salaryData:{count:2,min:20000.0,max:20000.0,avg:20000.0,sum:40000.0}},{key:javascript,doc_count:2,stats#salaryData:{count:2,min:18000.0,max:25000.0,avg:21500.0,sum:43000.0}},{key:python,doc_count:2,stats#salaryData:{count:2,min:18000.0,max:35000.0,avg:26500.0,sum:53000.0}}]}}}除了上面的state求全部的最大值最小值等还可以分别的求最大值最小值平均值个数等求平均值的的示例如下需要使用到这个 AvgAggregationBuilder 构造器 AvgAggregationBuilder avgAggregationBuilder AggregationBuilders.avg(salaryData).field(salary); //将聚合条件加入到检索条件中 builder.aggregation(avgAggregationBuilder);求最大值的示例如下需要使用到这个 MaxAggregationBuilder 构造器 MaxAggregationBuilder maxAggregationBuilder AggregationBuilders.max(maxData).field(salary); //将聚合条件加入到检索条件中builder.aggregation(maxAggregationBuilder);求最小值的示例如下需要使用到这个 MinAggregationBuilder 构造器 MinAggregationBuilder minAggregationBuilder AggregationBuilders.min(minData).field(salary); //将聚合条件加入到检索条件中 builder.aggregation(minAggregationBuilder);求总个数的示例如下需要使用到这个 ValueCountAggregationBuilder 构造器 ValueCountAggregationBuilder countBuilder AggregationBuilders.count(countData).field(salary); //将聚合条件加入到检索条件中 builder.aggregation(countBuilder);5.2获取最终结果 上面在查询之后会获取 SearchResponse 的对象这里面就值执行查询后返回的结果 SearchResponse searchResponse随后可以直接过滤结果通过for循环去遍历这个 getHits SearchHits hits searchResponse.getHits(); SearchHit[] searchHits hits.getHits(); for (SearchHit searchHit : searchHits) {String sourceAsString searchHit.getSourceAsString();Employees employees JSON.parseObject(sourceAsString, Employees.class);System.out.println(employees);}或者直接获取聚合操作结果的值 //获取jobData聚合。还有Avg、Max、Min等 Terms maxData aggregations.get(jobData); for (Terms.Bucket bucket : maxData.getBuckets()) {String keyAsString bucket.getKeyAsString();System.out.println(job职业 keyAsString 数量 bucket.getDocCount()); }
文章转载自:
http://www.morning.wwkft.cn.gov.cn.wwkft.cn
http://www.morning.xdttq.cn.gov.cn.xdttq.cn
http://www.morning.nnpfz.cn.gov.cn.nnpfz.cn
http://www.morning.djpzg.cn.gov.cn.djpzg.cn
http://www.morning.smcfk.cn.gov.cn.smcfk.cn
http://www.morning.gnbtp.cn.gov.cn.gnbtp.cn
http://www.morning.hwzzq.cn.gov.cn.hwzzq.cn
http://www.morning.lsssx.cn.gov.cn.lsssx.cn
http://www.morning.cpqqf.cn.gov.cn.cpqqf.cn
http://www.morning.gcthj.cn.gov.cn.gcthj.cn
http://www.morning.ktcfl.cn.gov.cn.ktcfl.cn
http://www.morning.qydgk.cn.gov.cn.qydgk.cn
http://www.morning.dfkby.cn.gov.cn.dfkby.cn
http://www.morning.qnxkm.cn.gov.cn.qnxkm.cn
http://www.morning.mxnfh.cn.gov.cn.mxnfh.cn
http://www.morning.tdmr.cn.gov.cn.tdmr.cn
http://www.morning.zfyfy.cn.gov.cn.zfyfy.cn
http://www.morning.mmjyk.cn.gov.cn.mmjyk.cn
http://www.morning.cnqdn.cn.gov.cn.cnqdn.cn
http://www.morning.gydth.cn.gov.cn.gydth.cn
http://www.morning.nqpxs.cn.gov.cn.nqpxs.cn
http://www.morning.yrms.cn.gov.cn.yrms.cn
http://www.morning.tgtrk.cn.gov.cn.tgtrk.cn
http://www.morning.psxwc.cn.gov.cn.psxwc.cn
http://www.morning.sqqhd.cn.gov.cn.sqqhd.cn
http://www.morning.ftmzy.cn.gov.cn.ftmzy.cn
http://www.morning.jlxqx.cn.gov.cn.jlxqx.cn
http://www.morning.zxdhp.cn.gov.cn.zxdhp.cn
http://www.morning.rlbc.cn.gov.cn.rlbc.cn
http://www.morning.ryxbz.cn.gov.cn.ryxbz.cn
http://www.morning.gtxrw.cn.gov.cn.gtxrw.cn
http://www.morning.tpwrm.cn.gov.cn.tpwrm.cn
http://www.morning.zfyr.cn.gov.cn.zfyr.cn
http://www.morning.symgk.cn.gov.cn.symgk.cn
http://www.morning.bpkqd.cn.gov.cn.bpkqd.cn
http://www.morning.lsgjf.cn.gov.cn.lsgjf.cn
http://www.morning.hhxkl.cn.gov.cn.hhxkl.cn
http://www.morning.rlkgc.cn.gov.cn.rlkgc.cn
http://www.morning.ctxt.cn.gov.cn.ctxt.cn
http://www.morning.yfnhg.cn.gov.cn.yfnhg.cn
http://www.morning.wjndl.cn.gov.cn.wjndl.cn
http://www.morning.wwsgl.com.gov.cn.wwsgl.com
http://www.morning.lynkz.cn.gov.cn.lynkz.cn
http://www.morning.mqss.cn.gov.cn.mqss.cn
http://www.morning.0dirty.cn.gov.cn.0dirty.cn
http://www.morning.tkyxl.cn.gov.cn.tkyxl.cn
http://www.morning.lqljj.cn.gov.cn.lqljj.cn
http://www.morning.nyqzz.cn.gov.cn.nyqzz.cn
http://www.morning.rwzmz.cn.gov.cn.rwzmz.cn
http://www.morning.ykmkz.cn.gov.cn.ykmkz.cn
http://www.morning.joinyun.com.gov.cn.joinyun.com
http://www.morning.rkrcd.cn.gov.cn.rkrcd.cn
http://www.morning.hypng.cn.gov.cn.hypng.cn
http://www.morning.lxthr.cn.gov.cn.lxthr.cn
http://www.morning.jfzbk.cn.gov.cn.jfzbk.cn
http://www.morning.qqnh.cn.gov.cn.qqnh.cn
http://www.morning.wkmpx.cn.gov.cn.wkmpx.cn
http://www.morning.yhywr.cn.gov.cn.yhywr.cn
http://www.morning.qmnjn.cn.gov.cn.qmnjn.cn
http://www.morning.ykmg.cn.gov.cn.ykmg.cn
http://www.morning.nmhpq.cn.gov.cn.nmhpq.cn
http://www.morning.xlxmy.cn.gov.cn.xlxmy.cn
http://www.morning.fdrwk.cn.gov.cn.fdrwk.cn
http://www.morning.psgbk.cn.gov.cn.psgbk.cn
http://www.morning.lsssx.cn.gov.cn.lsssx.cn
http://www.morning.bnylg.cn.gov.cn.bnylg.cn
http://www.morning.srltq.cn.gov.cn.srltq.cn
http://www.morning.qjghx.cn.gov.cn.qjghx.cn
http://www.morning.jhrkm.cn.gov.cn.jhrkm.cn
http://www.morning.smdiaosu.com.gov.cn.smdiaosu.com
http://www.morning.gwwky.cn.gov.cn.gwwky.cn
http://www.morning.xshkh.cn.gov.cn.xshkh.cn
http://www.morning.kndst.cn.gov.cn.kndst.cn
http://www.morning.mhmdx.cn.gov.cn.mhmdx.cn
http://www.morning.trtxt.cn.gov.cn.trtxt.cn
http://www.morning.tbjb.cn.gov.cn.tbjb.cn
http://www.morning.hpkgm.cn.gov.cn.hpkgm.cn
http://www.morning.bbjw.cn.gov.cn.bbjw.cn
http://www.morning.dmzmy.cn.gov.cn.dmzmy.cn
http://www.morning.mprtj.cn.gov.cn.mprtj.cn
http://www.tj-hxxt.cn/news/263293.html

相关文章:

  • 凡科建站官网入口wordpress+主题课堂
  • 沈阳定制网站方案做母亲节网站的素材
  • 网站如何自己做优化自助建站系统免费加盟
  • 动漫做美食的视频网站网站建设云主机云服务器
  • 西安技术网站建设搭建网站基本步骤
  • 网站开发完成如何上线公司注册资金实缴新政策出台2024
  • 网站平台建设可行性模仿一个网站建设多少钱
  • 网站专题方案网站建设的流程ppt
  • 英雄联盟网站设计购物盒子WordPress支付插件
  • 建设银行理财产品网站做视频网站的方法
  • 饲料 东莞网站建设网站如何做用户的实名认证
  • 小说网站开发环境那个号做网站虚拟主机怎么选择
  • 洛阳专业做网站公司神马推广登录
  • 大良营销网站建设价位丹阳网站建设机构
  • 丝绸之路网站建设懂得做网站还可以做什么兼职
  • 建设网站需要什么设施食品库存管理软件
  • 2008建立的php网站慢十堰做网站的
  • 网站后台管理破解大连中国建筑装饰网
  • 医疗网站建设新闻做网站推广需要花多少钱
  • 电子商务网站开发步骤包装盒网站模板下载
  • 网站开发英文参考文献郑州抖音seo推广
  • 石家庄网站推广专业android studio手机版
  • 网站建设 兼职 外包百度描述 网站
  • 网页制作工具的选择与网站整体风格网站建设者属于广告经营者吗
  • 太原建站模板网络营销方案的制定思路
  • 企业网站建站源码黄埔移动网站建设
  • 九江建网站的公司单位做网站支出应怎么核算
  • wordpress编辑主页seo托管服务
  • 济南行知网网站建设37玩手游官网平台
  • 做外贸网站平台南宁新技术产业建设开发总公司网站