I use the Java RestHighLevelClient, and it works fine with localhost elastic search (in which I pass "localhost" and 9200, "http") like the example in here
But how do I use this for elastic search cloud? and I suppose the host would be ".us-east-1.aws.found.io" and my port will be "9203" and scheme is always "https"?
There is a user/password associated with the cloud version... how to pass that along?
The following works perfectly fine in a little standalone Java Application (where the constants are pointing to my instance)...
RestHighLevelClient restHighLevelClient = null;
if (!"localhost".equals(ELASTIC_HOST)) {
RestClientBuilder builder = RestClient
.builder(new HttpHost(ELASTIC_HOST, Integer.parseInt(ELASTIC_PORT), ELASTIC_SCHEME));
// if not localhost, specify username and password
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials(ELASTIC_USER, ELASTIC_PASSWORD));
builder.setHttpClientConfigCallback(
httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
builder.setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder.setConnectTimeout(40000).setSocketTimeout(50000)).setMaxRetryTimeoutMillis(60001);
restHighLevelClient = new RestHighLevelClient(builder);
} else {
restHighLevelClient = new RestHighLevelClient(
RestClient.builder(new HttpHost(ELASTIC_HOST, Integer.parseInt(ELASTIC_PORT), "http")));
}
try {
LOGGER.info("ping");
boolean pingResult = restHighLevelClient.ping(RequestOptions.DEFAULT);
LOGGER.info("pingResult=" + pingResult);
} catch (Exception e) {
LOGGER.error("Can't even ping: ",e);
}
However, inside a Web application (in a data access object)... this ping will fail (and any search, show indices etc would also fail) with a Timeout.
03-21-2019 12:20:55 ERROR ElasticsearchDAO:388 - Can't even ping:
java.io.IOException: listener timeout after waiting for [60001] ms
at org.elasticsearch.client.RestClient$SyncResponseListener.get(RestClient.java:899)
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:227)
at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1256)
at org.elasticsearch.client.RestHighLevelClient.ping(RestHighLevelClient.java:372)
Any idea what extra steps a Java web application may need to access elastic search on cloud?
Thanks @dadoonet, yes, conflicting maven artifact was the culprit.
I was able to use mvn dependency:tree to figure that elastic search uses a particular version of apache httpcomponent which uses a particular version of commons-codec... and I had another place that uses a different version which conflicted it.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.