elasticsearch java無法連接、
問題描述
我在本地啟動的ES,使用CURL進行調用是沒問題的,但是在代碼中無法連接。
Settings settings = Settings.builder().put('cluster.name', 'cluster-tony').build();try { //創建client TransportClient client = new PreBuiltTransportClient(settings) .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName('192.168.0.230'), 9200)); //搜索數據 GetResponse response = client.prepareGet('blog', 'article', '1').execute().actionGet(); //輸出結果 System.out.println(response.getSourceAsString()); //關閉client client.close();} catch (UnknownHostException e) { e.printStackTrace();}
在瀏覽器中訪問的結果:
{ 'name' : '7BaVGc5', 'cluster_name' : 'cluster-tony', 'cluster_uuid' : 'ctTbTQfvTUyzV00JMWPfyA', 'version' : { 'number' : '5.3.0', 'build_hash' : '3adb13b', 'build_date' : '2017-03-23T03:31:50.652Z', 'build_snapshot' : false, 'lucene_version' : '6.4.1' }, 'tagline' : 'You Know, for Search'}
問題解答
回答1:知道原因了,pom中jar重復了
相關文章:
