ElasticSearch(5)--使用Java客户端删除文档
2018-02-06 18:18
375 查看
使用Java客户端删除文档
package com.es.demo;
import java.net.InetAddress;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* 删除文档
*
* @author Beck
* @date 2018年2月6日
*/
public class TestES4 {
private static final String HOST = "127.0.0.1";
private static final int PORT = 9300;
private TransportClient client = null;
// 删除文档
@Test
public void deleteDocument(){
DeleteResponse response = this.client
.prepareDelete("eshop", "product", "AWFluEB6rUhLs_HfwSwu")
.get();
System.out.println(response.getVersion());
}
// 获取客户端
@Before
public void getClient() throws Exception{
client = TransportClient.builder()
.build()
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(HOST), PORT));
}
// 关闭客户端
@After
public void closeClient(){
if (this.client != null){
this.client.close();
}
}
}
package com.es.demo;
import java.net.InetAddress;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* 删除文档
*
* @author Beck
* @date 2018年2月6日
*/
public class TestES4 {
private static final String HOST = "127.0.0.1";
private static final int PORT = 9300;
private TransportClient client = null;
// 删除文档
@Test
public void deleteDocument(){
DeleteResponse response = this.client
.prepareDelete("eshop", "product", "AWFluEB6rUhLs_HfwSwu")
.get();
System.out.println(response.getVersion());
}
// 获取客户端
@Before
public void getClient() throws Exception{
client = TransportClient.builder()
.build()
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(HOST), PORT));
}
// 关闭客户端
@After
public void closeClient(){
if (this.client != null){
this.client.close();
}
}
}
相关文章推荐
- ElasticSearch(4)--使用Java客户端更新文档
- Elasticsearch Java API(九)--删除文档的field以及field的属性
- Elasticsearch Java API(七)--删除文档的field以及field的属性
- elasticsearch java api使用,es java封装
- ElasticSearch Java Api(四) -删除索引
- ZooKeeper之Java客户端API使用—删除节点。
- ElasticSearch Java Api(四) -删除索引
- MongoDB_Java连接mongo 使用Java从集合中删除文档
- ElasticSearch学习13_ElasticSearch RESTful搜索引擎_Java Jest使用入门
- ELK研究(一):elasticsearch java api接口操作ES集群 ---TransportClient的使用介绍 bulk批量提交数据
- Elasticsearch java API (8)删除API
- ElasticSearch Java Api(四) -删除索引
- ElasticSearch(2)--使用Java客户端创建文档
- ELK研究(一):elasticsearch java api接口操作ES集群 ---TransportClient的使用介绍 bulk批量提交数据
- RabbitMQ的java客户端API使用文档中文版
- elasticSearch Java Api使用
- 在JAVA项目中,使用JasperReports与iReport,直接连接打印机可打印(word excel xml pdf )文档
- JAVA调用Tuxedo服务——使用JNI封装Tuxedo客户端的一个例子
- 在eclipse中使用中文JAVA api文档
- JAVA调用Tuxedo服务——使用JNI封装Tuxedo客户端的一个例子