java以TransportClient方式连接elasticsearch

1.在pom.xml添加以下dependency


            org.elasticsearch.client
            transport
            5.6.3



            org.elasticsearch
            elasticsearch
            5.6.3


            org.apache.logging.log4j
            log4j-core
            2.9.1


            org.apache.logging.log4j
            log4j-api
            2.9.1

2.创建log4j.properties

appender.console.type = Console
appender.console.name = console
appender.console.layout.type = PatternLayout

rootLogger.level = info
rootLogger.appenderRef.console.ref = console

3.连接测试代码

Settings settings =Settings.builder().put("cluster.name", "my-application").build();
TransportClient client = new PreBuiltTransportClient(settings);
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"),Integer.parseInt("9300")));
ClusterStateResponse response = client.admin().cluster().prepareState().execute().actionGet();
System.out.println(response.getState());
client.close();
java以TransportClient方式连接elasticsearch_第1张图片
微信

java以TransportClient方式连接elasticsearch_第2张图片
支付宝

你可能感兴趣的:(java以TransportClient方式连接elasticsearch)