继续上个随笔:

那么我们只需要修改controller中文件就可以完成相关操作

本次主要是对文档得操作:

更新文档:

package com.cxy.elasticsearch.controller;

import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.snapshots.SnapshotShardsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import javax.xml.transform.Source;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map; @RestController
public class EsindexController {
@Autowired
RestHighLevelClient client; @Autowired
RestClient restClient; @RequestMapping(value = "/updatedoc",method = RequestMethod.GET)
public String updatedoc(){
UpdateRequest updateRequest = new UpdateRequest("chenxuyou3","doc","ekBpCG8BAmmLmqjtgRwU");
HashMap<String, String> stringStringHashMap = new HashMap<>();
stringStringHashMap.put("name","Ealsticseach学习实战");
updateRequest.doc(stringStringHashMap);
UpdateResponse update =null;
try {
update= client.update(updateRequest, RequestOptions.DEFAULT);
} catch (IOException e) {
e.printStackTrace();
}
RestStatus status = update.status();
System.err.println(status); return "ok" ;
}
@RequestMapping(value = "/deletedoc",method = RequestMethod.GET)
public String deletedoc(){
String id ="e0CECG8BAmmLmqjt6hwW";
DeleteRequest deleteRequest = new DeleteRequest("chenxuyou3", "doc", id);
DeleteResponse delete = null;
try {
delete = client.delete(deleteRequest, RequestOptions.DEFAULT);
} catch (IOException e) {
e.printStackTrace();
}
RestStatus status = delete.status();
System.err.println(status); return "ok" ;
} }

调用接口:

localhost:8085/updatedoc

成功:

调用删除接口,删除得是数据第一条:

接口:

可以看到已经删除了。所以对文档得增加,删除,修改,查询已经完成了,下个随便将会写对文档得精确,模糊,分数查询

springboot整合es客户端操作elasticsearch(三)的更多相关文章

  1. springboot整合es客户端操作elasticsearch(五)

    springboot整合es客户端操作elasticsearch的总结: 客户端可以进行可以对所有文档进行查询,就是不加任何条件: SearchRequest searchRequest = new ...

  2. springboot整合es客户端操作elasticsearch(二)

    在上章节中整合elasticsearch客户端出现版本问题进行了处理,这章来进行springboot整合得操作 环境:elaticsearch6.2.1,springboot 2.1.8 客户端版本采 ...

  3. springboot整合es客户端操作elasticsearch(四)

    对文档查询,在实际开发中,对文档的查询也是偏多的,记得之前在mou快递公司,做了一套事实的揽件数据操作,就是通过这个来存储数据的,由于一天的数据最少拥有3500万数据 所以是比较多的,而且还要求查询速 ...

  4. SpringBoot整合ES+Kibana

    前言:最近在写一个HTTP代理服务器,记录日志使用的是ES,所以涉及到SpringBoot和ES的整合,整合完毕后又涉及到数据可视化分析,所以使用了Kibana进行管理,有些坑,需要记录一下 Spri ...

  5. 使用Java客户端操作elasticsearch(二)

    承接上文,使用Java客户端操作elasticsearch,本文主要介绍 常见的配置 和Sniffer(集群探测) 的使用. 常见的配置 前面已介绍过,RestClientBuilder支持同时提供一 ...

  6. 使用Java客户端操作elasticsearch

    Java REST客户端有两种风格: Java低级别REST客户端(Java Low Level REST Client,以后都简称低级客户端算了,难得码字):Elasticsearch的官方low- ...

  7. ElasticSearch(三)springboot整合ES

    最基础的整合: 一.maven依赖 <parent> <groupId>org.springframework.boot</groupId> <artifac ...

  8. SpringBoot 整合es(elasticsearch)使用elasticsearch-rest-high-level-client实现增删改

    引入依赖 <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok< ...

  9. springboot整合rabbitmq客户端连接报超时异常问题解决:An unexpected connection driver error occured java.net.SocketException: Socket Closed,java.util.concurrent.TimeoutException

    我用的是springboot2.0.6版本,对应的ampq也是2.0.6版本,然后启动一直报: 还有java.util.concurrent.TimeoutException, 用户授权什么的都对,很 ...

随机推荐

  1. BZOJ 4522: [Cqoi2016]密钥破解 (Pollard-Rho板题)

    Pollard-Rho 模板 板题-没啥说的- 求逆元出来后如果是负的记得加回正数 CODE #include<bits/stdc++.h> using namespace std; ty ...

  2. 题解 [BZOJ4886] 叠塔游戏

    题面 解析 这是个有趣的建图题啊. 首先我们可以发现,宽度严格递增是没什么用的. 因为实际上我们在旋转完以后, 矩形的顺序是可以随便排的. 因此只要保证宽度互不相同就行了. 然后,我们对长和宽离散化, ...

  3. 基于sed 的猫狗游戏

    1.测试文件 [root@L shells]# cat catDog.txt snake snake pig bird dog cat snake pig bird snake cat bird do ...

  4. luogu 4411 [BJWC2010]取数游戏 约数+dp

    不大难的dp,暴力拆一下约数然后按照约数来统计即可. 注意:vector 很慢,所以一定特判一下,如果没有该数,就不要添加. Code: #include <bits/stdc++.h> ...

  5. codeforces865C

    Gotta Go Fast CodeForces - 865C You're trying to set the record on your favorite video game. The gam ...

  6. deepin Linux 安装+工作学习配置

    一 安装 在官网下载 U盘安装,神舟优雅x4开机按F7,选择U盘启动. U盘安装器在下载的镜像文件中. 二 配置 升级最新系统 设置root用户密码: dawn@dawn-PC:~$ sudo pas ...

  7. 堡垒机前戏——paramiko

    提要:在写堡垒机之前,我们必须要了解paramiko这个第三方库.有关于python的第三方库的安装很简单,可以自行百度. 该模块基于SSH用于连接远程服务器并执行相关操作. SSHClient 用于 ...

  8. [dos]切换工作目录

    dos切换目录: 最快速的方法: cd /d D:\your\heart 常规步骤: 1. d:  先必须切换盘符 2. cd D:\your\heart,其次切换工作目录

  9. JavaWeb_(Spring框架)在Struts+Hibernate框架中引入Spring框架

    spring的功能:简单来说就是帮我们new对象,什么时候new对象好,什么时候销毁对象. 在MySQL中添加spring数据库,添加user表,并添加一条用户数据 使用struts + hibern ...

  10. [51nod1789] 跑得比谁都快

    题面 题解 设\(f[i]\)为根节点到\(i\)的最小耗时 设\(S\)为\(i\)的祖先集合, 可以得到 \[ f[i] = min(f[j] + (i - j)^p),j \in S \] 对于 ...