弹性搜索Jest客户端中的HTTPS支持

时间:2016-12-19 13:07:10

标签: java ssl elasticsearch https jest

我正在尝试通过HTTPS连接HTTPS/SSL support连接elasticsearch。

代码如下

// trust ALL certificates
        SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
            public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
                return true;
            }
        }).build();

        // skip hostname checks
        HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE;

        SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
        SchemeIOSessionStrategy httpsIOSessionStrategy = new SSLIOSessionStrategy(sslContext, hostnameVerifier);

        JestClientFactory factory = new JestClientFactory();
        factory.setHttpClientConfig(new HttpClientConfig.Builder("https://localhost:9200")
                        .defaultSchemeForDiscoveredNodes("https") // required, otherwise uses http
                        .sslSocketFactory(sslSocketFactory) // this only affects sync calls
                        .httpsIOSessionStrategy(httpsIOSessionStrategy) // this only affects async calls
                        .build());            

        JestClient client = factory.getObject();

        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
        searchSourceBuilder.query(QueryBuilders.matchAllQuery());                     
         Search search = new Search.Builder(searchSourceBuilder.toString())                
                .addIndex(INDEX)
                .addType(TYPE)                
                .setParameter(Parameters.SIZE, 2)
                .setParameter(Parameters.SCROLL, "5m")               
                .build();
             JestResult result = client.execute(search);

我可以使用http连接进行连接。但是当我尝试使用HTTPS连接进行连接时,我收到了以下错误

Error

如果你弄清楚这个错误,请告诉我。代码有什么问题吗?

0 个答案:

没有答案