8.3 SpringBoot集成ElasticSearch之删除文档

8.3 SpringBoot集成ElasticSearch之删除文档,第1张

8.3 SpringBoot集成ElasticSearch之删除文档

1.po开发
项目目录“/src/main/java/com/example/es”下新建po目录,并在po目录下新建Employee实体类,具体代码如下。

@Data
public class Employee implements IdProvider {
    @JsonProperty("id")
    private String id;

    @JsonProperty("name")
    private String name;

    @JsonProperty("age")
    private Integer age;

    @JsonProperty("birthday")
    private String birthday;

    @JsonProperty("job")
    private String job;

    @JsonProperty("salary")
    private Float salary;

    @Override
    public String getId() {
        return id;
    }
}

2.mapper开发
在项目目录“/src/main/java/com/example/es”下新建mapper目录,并在mapper目录下新建EmployeeMapper接口,具体代码如下。

@EasyMapper(indices = "employee", clusterRouter = "sampleCluster")
public interface EmployeeMapper {
   
    @Delete
    Boolean deleteEmployeeBoolean(String id);

    
    @Delete
    void deleteEmployeeVoid(String id);

    
    @Delete
    RestStatus deleteEmployee(Employee employee);

    
    @Delete
    DeleteResponse deleteEmployeeDeleteResponse(String id);

    
    @Delete
    RestStatus deleteEmployee(String id);

    
    @Delete
    CompletableFuture deleteEmployeeBooleanFuture(String id);

    
    @Delete
    CompletableFuture deleteEmployeeVoidFuture(String id);
}

3.controller开发
在项目目录“/src/main/java/com/example/es”下新建controller目录,并在controller目录下新建EmployeeController类,以deleteEmployee接口为例演示开发步骤,具体代码如下。

@RestController
@RequestMapping("/employee")
public class EmployeeController {
    @Resource
    private EmployeeMapper employeeMapper;

    @ResponseBody
    @RequestMapping(value = "/deleteEmployee", method = RequestMethod.DELETE)
    public RestStatus deleteEmployee(@RequestBody Employee employee) {
        return employeeMapper.deleteEmployee(employee);
    }
}

4.测试
启动项目,然后在postman中请求“http://localhost:8080/employee/deleteEmployee”,返回请求执行结果。

{
    "id":"10001"
}
"OK"

5.@Delete属性说明

序号属性名默认值说明1waitForActiveShards-2活动分片数量,-2时不指定分片数量,-1或all指定全部分片2timeout1m数值+时间单位(ms/s/m/h/M/y)3refreshPolicyRefreshPolicy.NONE默认不刷新

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5117998.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-17
下一篇 2022-11-17

发表评论

登录后才能评论

评论列表(0条)

保存