Java使用https连接ElasticSearch集群

时间:2019-01-21 08:10:33

标签: java elasticsearch

我为Elasticsearch集群安装了Search Guard。现在,我需要使用帐户密码连接到群集并使用https方法,但是根据我的代码,启动后,查询操作将出现错误,代码如下

使用下面的代码时,我会得到一个错误。

SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);

@Bean
public static RestHighLevelClient getInstance() {
    String esAuth = "Basic " + Base64.encode(user + ":" + password);
    Header[] defaultHeaders = new Header[]{new BasicHeader("Authorization", esAuth)};
    client = new RestHighLevelClient(
            RestClient.builder(new HttpHost(ip, port, "https"))
                    .setDefaultHeaders(defaultHeaders)
                    .setMaxRetryTimeoutMillis(150000)
                    .setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder
                            .setConnectTimeout(5000)
                            .setSocketTimeout(150000)));
    return client;
}

这是一个错误:

 java.lang.IllegalStateException: Request cannot be executed; I/O
 reactor status: STOPPED    at
 org.apache.http.util.Asserts.check(Asserts.java:46)
 ~[httpcore-4.4.10.jar:4.4.10]  at
 org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase.ensureRunning(CloseableHttpAsyncClientBase.java:90)
 ~[httpasyncclient-4.1.4.jar:4.1.4]     at
 org.apache.http.impl.nio.client.InternalHttpAsyncClient.execute(InternalHttpAsyncClient.java:123)
 ~[httpasyncclient-4.1.4.jar:4.1.4]     at
 org.elasticsearch.client.RestClient.performRequestAsync(RestClient.java:529)
 ~[elasticsearch-rest-client-6.4.3.jar:6.5.4]   at
 org.elasticsearch.client.RestClient.performRequestAsyncNoCatch(RestClient.java:514)
 ~[elasticsearch-rest-client-6.4.3.jar:6.5.4]   at
 org.elasticsearch.client.RestClient.performRequest(RestClient.java:226)
 ~[elasticsearch-rest-client-6.4.3.jar:6.5.4]   at
 org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1593)
 ~[elasticsearch-rest-high-level-client-6.5.4.jar:6.5.4]

0 个答案:

没有答案