2017-08-28 8 views
0

トランスポートクライアントを使用してリモートの弾性検索クラスタに接続しようとしています。リモート弾性検索クラスタへの接続に失敗しました

public class AuthenticationExample { 

    public static void main(String[] args) throws Exception { 
     if (args.length != 4) { 
      System.out.println("Usage :\njava -jar jarFile.jar clusterName hostIP port index"); 
      System.exit(0); 
     } 
     String clusterName = args[0]; 
     String hostName = args[1]; 
     int port = Integer.parseInt(args[2]); 
     String index = args[3]; 
     Settings settings = Settings.builder() 
       .put("cluster.name", clusterName).build(); 
     TransportClient esClient = new PreBuiltTransportClient(settings) 
       .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostName), port)); 
     esClient.threadPool().getThreadContext().putHeader("Authorization", "Basic " + Base64.encodeBase64("user:password".getBytes())); 
     System.out.println("Initialized successfully."); 
     boolean isIndexExists = false; 
     isIndexExists = esClient.admin().indices().prepareExists(index).execute().actionGet().isExists(); 
     if (isIndexExists) { 
      System.out.println("Is Index " + index + " Exists? " + isIndexExists); 
     } else { 
      System.out.println("Index " + index + " does not exist"); 
     } 
    } 
} 

私は上記のコードを実行し、jarFile.jar clusterNameのXXX.XXX.XXX.XXX 9300 INDEXNAME -jar

javaの

として、私は、次の例外 NoNodeAvailableException [Noneを取得していないのです構成されたノードが用意されています...また

私が使用してエンドポイントをヒットし、

カール-XGET -uユーザー:パスワードhttp://XXX.XXX.XXX.XXX:9200

次のように私は

{ 
    "name" : "XfJq4ed", 
    "cluster_name" : "elasticsearch", 
    "cluster_uuid" : "26yoM76iT8i-eo8k0E8y4g", 
    "version" : { 
    "number" : "5.4.0", 
    "build_hash" : "780f8c4", 
    "build_date" : "2017-04-28T17:43:27.229Z", 
    "build_snapshot" : false, 
    "lucene_version" : "6.5.0" 
    }, 
    "tagline" : "You Know, for Search" 
} 

は親切に私に解決策を与え、応答を取得しています。ありがとう

答えて

0

HTTPモジュールを許可しましたか?

あなたはここにつきオプションを見ることができます:https://www.elastic.co/guide/en/elasticsearch/reference/5.4/modules-http.html

+0

を、それがリモートサーバーであるので、私は唯一のユーザ名とパスワードを認識しています。私はHTTPモジュールを知らない。他の方法は、Javaクライアント側から行うには? – Janaarthan

+0

リモートサーバーの場合は、おそらくhttpが有効になっています。 、あまりにもこのリンクをチェックしてみて下さい: https://www.elastic.co/guide/en/elasticsearch/reference/5.4/modules-network.html 'discovery.zen.ping.unicast.hosts' - デフォルトは["127.0.0.1"、 "[:: 1]"] – Ansaldos

関連する問題