1,创建一个maven项目, ESTest,修改jre 为1.8.
下一步:
下一步:
2,添加jar包,transport,gson。配置maven,自动下载文档和源码,
3,创建com.cruise包, 创建类TestCon,设置ip地址,和端口,
package com.cruise; import java.net.InetAddress; 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 TestCON { private static String host="192.168.245.40"; private static int port=9300; @SuppressWarnings("resource") public static void main(String[] args) throws Exception{ TransportClient client = new PreBuiltTransportClient(Settings.EMPTY) .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host),port)); System.out.println(client); client.close(); } } |
4,启动项目测试,