@Override public boolean canConnect() { try { initialize(); return isIndexAvailable(); } catch (Exception e) { logger.warn("Failed to verify an ability to connect to index \"{}\" in cluster \"{}\" in Elasticsearch at {}:{} due to error: ", policyIndexName, elasticsearchProperties.getElasticsearchClusterName(), elasticsearchProperties.getElasticsearchHost(), elasticsearchProperties.getElasticsearchPort(), e); } return false; }
private Client getElasticClient() throws UnknownHostException { if (this.elasticClient == null) { Settings settings = Settings.settingsBuilder() .put("cluster.name", elasticsearchProperties.getElasticsearchClusterName()) .put("client.transport.ping_timeout", elasticsearchProperties.getElasticsearchTransportPingTimeout()) .build(); this.elasticClient = TransportClient.builder() .settings(settings) .build() .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(elasticsearchProperties.getElasticsearchHost()), elasticsearchProperties.getElasticsearchPort())); } return this.elasticClient; }