我在应用程序启动期间使用高级REST客户端(6.3.2版)创建了索引。我检查是否收到确认,但是我知道确认的错误值没有说明操作失败(它只是表示在默认超时时间内,客户端无法接收到确认)。
在这种情况下,我该怎么做才能确保确实创建了索引? 我正在寻找合适的响应代码,该代码可使我重试特定次数然后放弃
GetIndexRequest getIndexRequest = new GetIndexRequest();
boolean exists = restHighLevelClient.indices().exists(getIndexRequest);
if(!exists) {
//create a new index with default number of shards(5) and replica(1)
CreateIndexRequest createIndexRequest = Requests.createIndexRequest(elasticProps.getIndexName());
CreateIndexResponse createIndexResponse = restHighLevelClient.indices().create(createIndexRequest);
boolean acknowledged = createIndexResponse.isAcknowledged();
if(!acknowledged) {
LOGGER.warn("Could not receive acknowledge from all the nodes");
//wait and retry?
//
}
} else {
LOGGER.info("Index already exists");
}