文档-删除
# DeleteRequest
创建 Test08_Doc_Delete
package com.stt.demo;
import org.apache.http.HttpHost;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import java.io.IOException;
public class Test08_Doc_Delete {
public static void main(String[] args) throws IOException {
// 创建客户端
RestHighLevelClient client = new RestHighLevelClient(
RestClient.builder(new HttpHost("localhost", 9200, "http"))
);
// 构建请求
DeleteRequest request = new DeleteRequest().index("user").id("1001");
// 发送请求
DeleteResponse response = client.delete(request, RequestOptions.DEFAULT);
// 返回结果
System.out.println(response.toString());
// 关闭客户端
client.close();
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
返回
DeleteResponse[index=user,type=_doc,id=1001,version=3,result=deleted,shards=ShardInfo{total=2, successful=1, failures=[]}]
1
Last Updated: 2022/02/05, 15:58:51