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

网站怎么做自然优化川畅科技联系 网站设计

网站怎么做自然优化,川畅科技联系 网站设计,wordpress侧边导航主题,国开网站怎么做目录 12.5 RestClient操作索引库 12.5.1创建库 12.5.2 删除索引库 12.5.3 判断是否存在 12.6 RestClient操作文档 12.6.1 新增文档 12.6.2 查询文档 12.6.3 修改文档 12.6.4 删除文档 12.6.5 批量导入文档 12.5 RestClient操作索引库 酒店mapping映射 ​PUT /hotel{mappings: {properties: {id: {type: keyword,copy_to: all},name: {type: text,analyzer: ik_max_word},address: {type: keyword,index: false},price: {type: integer},score: {type: integer},brand: {type: keyword,copy_to: all},city: {type: keyword},starName: {type: keyword},business: {type: keyword},location: {type: geo_point},pic: {type: keyword,index: false},all: {type: text,analyzer: ik_max_word}}}} 导入依赖 !--elasticSearch依赖--dependencygroupIdorg.elasticsearch.client/groupIdartifactIdelasticsearch-rest-high-level-client/artifactIdversion7.12.1/version/dependency propertiesjava.version1.8/java.versionelasticsearch.version7.12.1/elasticsearch.version/properties 创建对象 SpringBootTestclass HotelIndexTest {private RestHighLevelClient client;​// 客户端初始化BeforeEachvoid setUp(){this.client new RestHighLevelClient(RestClient.builder(HttpHost.create(http://192.168.142.129:9200)));}​Testvoid tetsInit(){System.out.println(client);}​// 客户端销毁AfterEachvoid tearDown() throws IOException {this.client.close();}} client.indices()包含了操作索引库的所有方法 12.5.1创建库 Testvoid testCreateHotelIndex() throws IOException {// 1. 创建Request对象CreateIndexRequest request new CreateIndexRequest(hotel);// 2. 准备请求的参数request.source(MAPPING_TEMPLATE,XContentType.JSON);// 3. 发送请求   client.indices()的返回值包含了索引库额所有操作client.indices().create(request,RequestOptions.DEFAULT);} MAPPING_TEMPLATE是自定义的常量也就是上面创建索引库的语句 12.5.2 删除索引库 Testvoid testDeleteIndex() throws IOException {// 1. 创建request对象DeleteIndexRequest request new DeleteIndexRequest(hotel);// 2. 发送请求client.indices().delete(request,RequestOptions.DEFAULT);} 12.5.3 判断是否存在 Testvoid testExistIndex() throws IOException {// 1. 创建request对象GetIndexRequest request new GetIndexRequest(hotel);// 2. 发送请求boolean exists client.indices().exists(request, RequestOptions.DEFAULT);// 3. 输出System.out.println(exists ? 索引库存在 : 索引库不存在);} 12.6 RestClient操作文档 12.6.1 新增文档 Testvoid testIndexDocument() throws IOException {// 在数据库查到数据Hotel hotel iHotelService.getById(61083L);HotelDoc hotelDoc new HotelDoc(hotel); // 经度 纬度 拼接之后的对象 ,即索引库需要的类型// 1. 创建请求对象IndexRequest request new IndexRequest(hotel).id(hotel.getId().toString());// 2. 准备json文档 把查到的对象转换成json对象request.source(JSON.toJSONString(hotelDoc),XContentType.JSON);// 3. 发送请求client.index(request,RequestOptions.DEFAULT);} 12.6.2 查询文档 Testvoid testGetDocumentById() throws IOException {// 1. 准备requestGetRequest request new GetRequest(hotel, 61083);// 2. 发送请求GetResponse response client.get(request, RequestOptions.DEFAULT);// 3. 从响应中解析对象String json response.getSourceAsString();// 4. 把json转成HotelDoc对象HotelDoc hotelDoc JSON.parseObject(json, HotelDoc.class);System.out.println(hotelDoc);} 12.6.3 修改文档 第二种更新方式即局部更新的代码 : Testvoid testUpdateDocumentById() throws IOException {// 1. 准备RequestUpdateRequest request new UpdateRequest(hotel, 61083);// 2. 准备请求参数request.doc(age, 18,name,Rose);// 3. 发送请求client.update(request,RequestOptions.DEFAULT);} 12.6.4 删除文档 Testvoid testDeleteDocumentById() throws IOException {// 1. 准备requestDeleteRequest request new DeleteRequest(hotel,61083);// 2. 发送请求client.delete(request,RequestOptions.DEFAULT);} 12.6.5 批量导入文档 Testvoid testBulk() throws IOException {// 批量查询酒店数据ListHotel hotels iHotelService.list();// 1. 创建Bulk请求BulkRequest request new BulkRequest();// 2. 准备参数 添加多个新增的requestfor (Hotel hotel : hotels) {// 把hotel转成hotelDoc对象HotelDoc hotelDoc new HotelDoc(hotel);request.add(new IndexRequest(hotel).id(hotelDoc.getId().toString()).source(JSON.toJSONString(hotelDoc),XContentType.JSON));}​// 3. 发送请求client.bulk(request,RequestOptions.DEFAULT);}
http://www.hkea.cn/news/14575173/

相关文章:

  • 营销型网站建设需要懂什么网站改名 seo
  • 海原网站建设做挖机配件销售的网站
  • 北京市建设教育协会网站查询系统百姓网
  • 网站里的做菠菜提升网站开发效率
  • 找人做网站安全吗wordpress论坛模版
  • 深圳做分销网站建设做微信公众号的是哪个网站吗
  • 新乡建设网站公司网站建设企
  • 标准网站是哪个四川省建设厅职改办网站
  • 无锡网站app微信号网站信息同步
  • 南京市秦淮区建设局网站中山专业做网站
  • 新乡商城网站建设价格免费下载app软件的网站
  • 手机设计培训网站建设福田瑞沃e3
  • 用wordpress付费网站北京展示型网站建设价格
  • 网站违规关键词网站建设流程图在线制作
  • 客户拒绝做网站的理由如何推广自己的个人网站呢
  • ps拼合网站截图怎么做百度引流推广怎么做
  • 安徽网站推广营销设计百度贴吧官网入口
  • 知名企业名称有哪些seo和sem的区别
  • 网站建设模板源码海城百度公司 海城网站建设
  • 外部链接链轮的建设对于网站提哈尔滨网站建设哪家好
  • 百度云服务器做asp网站新闻发布会主题
  • 网站没有后台登陆文件夹网站未备案wordpress
  • 吉林省网站建设许昌做网站汉狮网络
  • 网站建设答辩问题促销式软文案例
  • 电子商务网站怎么做素材包阿里巴巴网站建设论文
  • 电子商务网站建设 试题河南网站制作公司
  • 河北建设厅网站登录密码错误网站内容过滤
  • 单位网站设计建议书做网站最基本
  • 深圳房地产网站开发wordpress文章和页面的区别
  • 金华网站定制公司保健品网站建设案例