Elasticsearch 5.X Java API 创建客户端
程序员文章站
2022-07-05 14:19:43
...
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
public class CreateClient
{
public static void main(String[] args)
{
// elasticsearch为集群名称,根据elasticsearch.yml中cluster.name设置,默认elasticsearch
Settings settings = Settings.builder().put("cluster.name", "elasticsearch").build();
TransportClient client = null;
try
{
client = new PreBuiltTransportClient(settings).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300));
}
catch (UnknownHostException e)
{
e.printStackTrace();
}
// index:索引,type:类型,id:文档id
GetResponse response = client.prepareGet("hbdss", "patient", "1").execute().actionGet();
System.out.println(response.getSourceAsString());
client.close();
}
}
上一篇: jdk源码阅读笔记-Integer
推荐阅读
-
Elasticsearch Java Rest Client API 整理总结 (一)
-
JAVA WEB快速入门之从编写一个基于SpringBoot+Mybatis快速创建的REST API项目了解SpringBoot、SpringMVC REST API、Mybatis等相关知识
-
Elasticsearch Java Rest Client API 整理总结 (二) —— SearchAPI
-
elasticsearch FunctionScore Java API sample
-
Elasticsearch Java Rest Client API 整理总结 (三)——Building Queries
-
Elasticsearch Java API 的使用(14)—优化索引创建之setting设置、写入优化
-
Java客户端API
-
Elasticsearch 5.X Java API 创建客户端
-
Elasticsearch Java REST高级客户端 MultiSearch Api
-
ZooKeeper API实战创建客户端