【问题标题】:Jest : ProtocolException: Target host is not specified开玩笑:ProtocolException:未指定目标主机
【发布时间】:2016-12-09 06:55:29
【问题描述】:

这是我第一次使用 Jest for Elasticsearch。我正在使用以下代码:

  public static JestClient getJestClient(ContainerRequestContext crc) {

            JSONObjeect elasticsearchServers = new JSONObject();
            elasticsearchServers.putAll((Map) crc.getProperty("serverProperties"));
            List<String> connectionUrls = new ArrayList<String>();

            Set serverSet = elasticsearchServers.entrySet();
            Iterator serverIterator = serverSet.iterator();
            while (serverIterator.hasNext()) {
                Map.Entry pair = (Map.Entry) serverIterator.next();
                connectionUrls.add(String.valueOf(pair.getValue()));
            }
            return buildJestClient(connectionUrls);
        }


    public static JestClient buildJestClient(List<String> connectionUrls) {
        final Builder builder = new Builder(connectionUrls)
                .multiThreaded(true);

        builder.gson(JestRichResult.createGsonWithDateFormat());
        HttpClientConfig clientConfig = builder.build();

        // Construct a new Jest client according to configuration via factory
        JestClientFactory factory = new JestClientFactory();
        factory.setHttpClientConfig(clientConfig);
        return factory.getObject();
    }

我正在尝试创建索引:

CreateIndex createIndex = new CreateIndex.Builder("inde").build();
jestClient.execute(createIndex);

但我面临以下错误:

org.apache.http.ProtocolException: Target host is not specified

我的 Elasticsearch 服务正在所有服务器上运行。

这是我的connectionUrls ips 列表:[1.2.3.4, 5.6.7.8, 10.11.12.13]

我在这里做错了什么?

【问题讨论】:

    标签: jestjs


    【解决方案1】:

    我做错了,我只提供了服务器的 IP 地址,但它应该是完整的地址,例如:

    http://1.2.3.4:9200

    所以我更改了添加 connectionUrls 的行 connectionUrls.add("http://"+String.valueOf(pair.getValue())+":9200");

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-07-12
      • 1970-01-01
      • 2020-10-14
      • 2021-09-17
      • 2017-11-01
      • 2018-06-02
      相关资源
      最近更新 更多