【问题标题】:Connection to remote elastic search cluster fails连接到远程弹性搜索集群失败
【发布时间】:2017-08-28 21:47:51
【问题描述】:

我正在尝试使用传输客户端连接到远程弹性搜索集群。

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");
        }
    }
}

当我运行上面的代码时,如

java -jar jarFile.jar clusterName XXX.XXX.XXX.XXX 9300 indexName

我收到以下异常 NoNodeAvailableException[配置的节点都不可用:...

当我使用,

curl -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"
}

请给我一个解决方案。谢谢

【问题讨论】:

    标签: java elasticsearch


    【解决方案1】:

    您是否允许 HTTP 模块?

    您可以在此处查看可用选项:https://www.elastic.co/guide/en/elasticsearch/reference/5.4/modules-http.html

    【讨论】:

    • 由于是远程服务器,我只知道用户名和密码。我不知道 HTTP 模块。从 java 客户端还有其他方法吗?
    • 因此,如果它是远程服务器,则可能启用了 http。请也查看此链接:elastic.co/guide/en/elasticsearch/reference/5.4/…'discovery.zen.ping.unicast.hosts' - 默认为 ["127.0.0.1", "[::1]"]
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多