第2講 . java連結ElasticSearch
阿新 • • 發佈:2018-11-15
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,啟動專案測試,