I have a requirement where i need to apply patches, create indices through resthighlevelclient and use elastic if elastic is up , otherwise switch to postgres.
let's suppose elastic service is down. when i try to apply patch , through resthighlevelclient it gives connection refused error and fails. Before applying patches or creating indices ,can we somehow know that elastic is down, through resthighlevelclient?
Please don't post images of text as they are hard to read, may not display correctly for everyone, and are not searchable.
Instead, paste the text and format it with </> icon or pairs of triple backticks (```), and check the preview window to make sure it's properly formatted before posting it. This makes it more likely that your question will receive a useful answer.
It would be great if you could update your post to solve this.
Here most likely I'd wrap the info() call in its own try - catch.
It indicates that the cluster is not reachable. What kind of other information are you expecting?
Also please format your code, logs or configuration files using </> icon as explained in this guide and not the citation button. It will make your post more readable.
Or use markdown style like:
```
CODE
```
This is the icon to use if you are not using markdown format:
There's a live preview panel for exactly this reasons.
Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.
@dadoonet In this way, through exception handling, we need to understand whether the elastic cluster is up or not.
Is there a way without exception handling?
try {
MainResponse info = this.esClient.info(RequestOptions.DEFAULT);
logger.info("Connected to {} running version {}", clusterUrl, info.getVersion().getNumber());
try {
this.esClient.indices().create(new CreateIndexRequest("myindex"), RequestOptions.DEFAULT);
logger.info("New index myindex has been created");
} catch (ElasticsearchStatusException e) {
if (e.status().getStatus() != 400) {
logger.warn("can not create index and mappings", e);
} else {
logger.debug("Index myindex was already existing. Skipping creating it again.");
}
}
} catch (IOException e) {
// Fail the process here
}
If you need something else, could you clarify the exact use case?
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.