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

什么网站可以查建筑工程项目九度互联网站推广公司

什么网站可以查建筑工程项目,九度互联网站推广公司,wordpress 新建媒体库,便利的合肥网站建设目录 一、集成Spring Boot 1、创建项目 2、pom文件 查看springboot集成的依赖 3、增加es的config类 二、索引相关API 1、创建索引 2、获取索引#xff0c;判断其是否存在 3、删除索引 三、文档相关API 1、添加文档 2、获取文档#xff0c;判断是否存在 3、获取文档…目录 一、集成Spring Boot 1、创建项目 2、pom文件 查看springboot集成的依赖 3、增加es的config类 二、索引相关API 1、创建索引 2、获取索引判断其是否存在 3、删除索引 三、文档相关API 1、添加文档 2、获取文档判断是否存在 3、获取文档信息 4、更新文档信息 5、删除文档信息 6、同文档批量导入数据 7、条件查询文档信息 一、集成Spring Boot Java使用对应的rest风格调用ES是通过client依赖包进行操作的 配置需要的 maven 依赖 dependencygroupIdorg.elasticsearch.client/groupIdartifactIdelasticsearch-rest-high-level-client/artifactIdversion7.17.24/version /dependency 1、创建项目 如果创建项目后拉取不到对应依赖springboot 可以选用低一些的稳定版本例如 2.3.2.RELEASE 版本 2、pom文件 查看springboot集成的依赖 当然也可自定义ES版本 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-elasticsearch/artifactId/dependency 3、增加es的config类 package com.example.elasticsearch_springboot_demo.config;import org.apache.http.HttpHost; import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestHighLevelClient; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;Configuration public class ElasticSearchClientConfig {Beanpublic RestHighLevelClient restHighLevelClient(){RestHighLevelClient client new RestHighLevelClient(RestClient.builder(new HttpHost(localhost, 9200, http),new HttpHost(localhost, 9201, http)));return client;} } 二、索引相关API 1、创建索引 SpringBootTest class ElasticSearchSpringbootDemoApplicationTests {AutowiredQualifier(restHighLevelClient)private RestHighLevelClient client;/*** 【索引相关】索引创建*/Testvoid testCreateIndex() throws IOException {// 1、创建索引请求CreateIndexRequest request new CreateIndexRequest(m_index);// 2、客户端执行请求 IndicesClient执行创建请求 并获得响应结果CreateIndexResponse createIndexResponse client.indices().create(request, RequestOptions.DEFAULT);// 3、查看响应结果System.out.println(createIndexResponse);} } 2、获取索引判断其是否存在 SpringBootTest class ElasticSearchSpringbootDemoApplicationTests {AutowiredQualifier(restHighLevelClient)private RestHighLevelClient client;/*** 【索引相关】获取索引判断其是否存在*/Testvoid testExistIndex() throws IOException {// 1、获取索引请求GetIndexRequest request new GetIndexRequest(m_index);// 2、客户端执行请求 IndicesClient执行请求后获得是否存在结果boolean exists client.indices().exists(request, RequestOptions.DEFAULT);// 3、查看结果System.out.println(exists);} } 3、删除索引 SpringBootTest class ElasticSearchSpringbootDemoApplicationTests {AutowiredQualifier(restHighLevelClient)private RestHighLevelClient client;/*** 【索引相关】删除索引*/Testvoid testDeleteIndex() throws IOException {// 1、删除索引请求DeleteIndexRequest request new DeleteIndexRequest(m_index);// 2、客户端执行请求 IndicesClient执行删除请求 并获得响应结果AcknowledgedResponse delete client.indices().delete(request, RequestOptions.DEFAULT);// 3、查看结果System.out.println(delete.isAcknowledged());} } 三、文档相关API 先定义一个User类 Data AllArgsConstructor NoArgsConstructor Component public class User {private String name;private Integer age;} 1、添加文档 SpringBootTest class ElasticSearchSpringbootDemoApplicationTests {AutowiredQualifier(restHighLevelClient)private RestHighLevelClient client;/*** 【文档相关】添加文档*/Testvoid testAddDocument() throws IOException {// 1、user对象User user new User(marvin, 26);// 2、创建请求对象并组装文档数据IndexRequest request new IndexRequest(m_index);// 定义文档内容// 规则 put /m_index/_doc/1request.id(1);request.timeout(TimeValue.timeValueSeconds(1));request.timeout(1s);//将user数据放入请求jsonrequest.source(JSON.toJSONString(user), XContentType.JSON);// 3、客户端发送请求获取响应的结果IndexResponse indexResponse client.index(request, RequestOptions.DEFAULT);// 4、查看结果System.out.println(indexResponse.toString());// 对应的文档信息System.out.println(indexResponse.status());// 执行命令的返回状态} } 2、获取文档判断是否存在 get /index/doc/1 SpringBootTest class ElasticSearchSpringbootDemoApplicationTests {AutowiredQualifier(restHighLevelClient)private RestHighLevelClient client;/*** 【文档相关】获取文档判断是否存在 get /index/doc/1*/Testvoid testIsExistsDocument() throws IOException {GetRequest getRequest new GetRequest(m_index, 1);// 不获取返回的_source 的上下文getRequest.fetchSourceContext(new FetchSourceContext(false));getRequest.storedFields(_none_);boolean exists client.exists(getRequest, RequestOptions.DEFAULT);System.out.println(exists);} } 3、获取文档信息 SpringBootTest class ElasticSearchSpringbootDemoApplicationTests {AutowiredQualifier(restHighLevelClient)private RestHighLevelClient client;/*** 【文档相关】获取文档信息*/Testvoid testGetDocument() throws IOException {GetRequest getRequest new GetRequest(m_index, 1);GetResponse documentFields client.get(getRequest, RequestOptions.DEFAULT);System.out.println(documentFields.getSourceAsString());// 打印文档内容System.out.println(documentFields);// 返回的全部内容和命令是一样的} } 4、更新文档信息 SpringBootTest class ElasticSearchSpringbootDemoApplicationTests {AutowiredQualifier(restHighLevelClient)private RestHighLevelClient client;/*** 【文档相关】更新文档信息*/Testvoid testUpdateDocument() throws IOException {UpdateRequest updateRequest new UpdateRequest(m_index, 1);updateRequest.timeout(1s);User user new User(jerry, 28);updateRequest.doc(JSON.toJSONString(user), XContentType.JSON);UpdateResponse updateResponse client.update(updateRequest, RequestOptions.DEFAULT);System.out.println(updateResponse.status());} } 5、删除文档信息 SpringBootTest class ElasticSearchSpringbootDemoApplicationTests {AutowiredQualifier(restHighLevelClient)private RestHighLevelClient client;/*** 【文档相关】删除文档信息*/Testvoid testDeleteDocument() throws IOException {DeleteRequest deleteRequest new DeleteRequest(m_index, 1);deleteRequest.timeout(1s);DeleteResponse deleteResponse client.delete(deleteRequest, RequestOptions.DEFAULT);System.out.println(deleteResponse.status());} } 6、同文档批量导入数据 SpringBootTest class ElasticSearchSpringbootDemoApplicationTests {AutowiredQualifier(restHighLevelClient)private RestHighLevelClient client;/*** 【文档相关】特殊的批量导入数据*/Testvoid testBulkDocument() throws IOException {BulkRequest bulkRequest new BulkRequest();bulkRequest.timeout(10s);ListUser userList new ArrayList();userList.add(new User(marvin1, 26));userList.add(new User(marvin2, 26));userList.add(new User(marvin3, 26));userList.add(new User(marvin4, 26));userList.add(new User(marvin5, 26));userList.add(new User(marvin6, 26));// 批处理请求for (int i0; iuserList.size();i){// 批量更新和批量删除就再这里修改对应请求就可以了bulkRequest.add(new IndexRequest(m_index).id((i1)).source(JSON.toJSONString(userList.get(i)), XContentType.JSON));}BulkResponse bulkResponse client.bulk(bulkRequest, RequestOptions.DEFAULT);System.out.println(bulkResponse.hasFailures());// 是否失败返回false 代表成功} } 7、条件查询文档信息 SpringBootTest class ElasticSearchSpringbootDemoApplicationTests {AutowiredQualifier(restHighLevelClient)private RestHighLevelClient client;/*** 查询* searchRequest 搜索请求* SearchSourceBuilder 搜索条件构造*/Testvoid testSearch() throws IOException {// 1、创建搜索请求SearchRequest searchRequest new SearchRequest(m_index);// 2、构建搜索条件SearchSourceBuilder sourceBuilder new SearchSourceBuilder();/*** 查询条件可以使用QueryBuilders快速匹配*///精确匹配termQueryTermQueryBuilder termQueryBuilder QueryBuilders.termQuery(name, marvin);//匹配所有MatchAllQueryBuilder matchAllQueryBuilder QueryBuilders.matchAllQuery();sourceBuilder.query(termQueryBuilder);sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));// 3、将查询条件放入请求searchRequest.source(sourceBuilder);// 4、执行请求SearchResponse searchResponse client.search(searchRequest, RequestOptions.DEFAULT);// 5、所有结果都封装在 SearchHits 里面通过getHits()得到System.out.println(JSON.toJSONString(searchResponse.getHits()));System.out.println();//循环输出每一条数据结果为map结构for (SearchHit documentFields : searchResponse.getHits().getHits()){System.out.println(documentFields.getSourceAsMap());// 转换为map结构}} }
http://www.pierceye.com/news/323366/

相关文章:

  • 恭城网站建设中象做网站怎么样
  • 泰兴网站建设开发门户网站内容建设岗位职责
  • 单页网站有后台搜索引擎优化工具有哪些
  • 视频网站弹幕怎么做中小企业网站优化
  • 南充网站建设江宁外贸网站建设
  • 从事网站开发需要的证书泰安百度推广代理
  • 找工作哪个网站好2022查询网站备案显示划横线
  • 06627网页制作和网站建设如何制作自己的公司内部网站
  • 网站营销与推广方案百度大数据分析
  • 手机怎么做自己的网站做网站的公司广州
  • asp.net网站开发案例教程南京seo排名
  • 购物网站开发技术分销
  • 企业网站建设专家工业产品设计包括哪些
  • 潍坊网站开发高手重庆市设计院
  • 微信公众号平台网站开发WordPress破解分享
  • 东营网站建设服务商低价备案域名购买
  • 高校网站建设自查报告哪个外贸网站开发客户比较好用
  • 网站做付费推广都需要问什么wordpress小工具插件
  • 网站的建设技术有哪些北京一环都是住什么人
  • 做外贸soho网站的公司吗已有备案号新增网站备案要关闭原先的站点吗
  • 网站域名注册免费wordpress 让导航悬浮
  • 全景旅游网站项目建设湖南建筑公司网站
  • 做网批那个网站好免费视频素材库app
  • cms建站模板appseo网络优化是什么工作
  • 云落wordpress优化大师在哪里
  • 威海网站建设公司手机网站做落地页
  • 海宁建设局网站三网合一 网站建设
  • 1688货源网官方网站网站怎么做背景
  • 做阿里还是网站中小企业为什么要建设网站
  • 天津的网站建设做网站费用怎么入账