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

google网站质量电子商务专业就业方向女生

google网站质量,电子商务专业就业方向女生,手机网站搜索框代码,网页设计与网站建设标准教程目录 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{&…

目录

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依赖--><dependency><groupId>org.elasticsearch.client</groupId><artifactId>elasticsearch-rest-high-level-client</artifactId><version>7.12.1</version></dependency>

  <properties><java.version>1.8</java.version><elasticsearch.version>7.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 {// 批量查询酒店数据List<Hotel> 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.yayakq.cn/news/454262/

相关文章:

  • 网站做流量怎么赚钱的企业建设网站专业服务
  • 泉州网站开发联系薇网站建设自主开发的三种方式
  • 邯郸网站建设市场如何做网站的统计
  • 海口网站建设的开发方案织梦房产网站模板
  • 滨州网站建设hskj360企业介绍怎么写呢
  • 做资源下载网站违法吗网站管理员权限
  • 如何自助建站网站模版设计
  • 网站建设收费标准国内自建站
  • 网站营销咨询顾问wordpress阅读类主题
  • 做响应式网站价格crm管理系统软件哪个好
  • python做网站 不适合四川省建设领域信用系统网站
  • 如何做网站推广私人建设网站个类型好
  • 上海网站域名注册价格网站访问量查询
  • 虚拟主机可建站1个是不是只能放一个网站可以提升自己的网站
  • 佛山牛豹云网站开发福州建网站
  • 在线手机网站建设做直播网站有哪些
  • 网站购物系统制作雨辰资讯电子商务类网站开发韶关公司做网站
  • 徐州智能模板建站手机移动端网站建设宣传
  • 企业门户网站建设方案网站运营与管理规划书
  • 铁道部建设司网站动漫设计与制作工资多少
  • 中国制造网网站特色论述网站建设流程
  • 大连哪家做网站比较好网站备案没公司名称
  • 网站优化如何收费济源专业网站建设(制作网站)
  • 用jsp做的可运行的网站西部域名网
  • 温州哪里有网站c语言开发环境
  • 广州市住房和城乡建设局网站淘宝网页美工设计
  • 网站建设服务天软科技广州在线网站制作
  • 省建设厅网站安全生产标准化网络推广怎么收费
  • 济南做网站哪里好重庆 网站 备案 查询
  • python 自己做网站新城疫最快解决的办法