spring boot Check elastic search部署当前可用或不使用Java
我为elastic search CRUD操作创建了一个Java服务。我在下面给出了我的业务逻辑。我正在进行所有服务器端验证,在将数据插入索引之前,我必须检查elastic search部署是否当前可用,或者是否使用elastic search的RestHighLevelClient。我在下面给出了我的代码
public String createProfileDocument(EmployeeInformation document, String IndexName) throws Exception {
String Id = document.getId();
if (Strings.isNullOrEmpty(Id)) {
return "ID is null or empty";
}
else if(Strings.isNullOrEmpty(IndexName)) {
return "Index name is null or empty";
}
else if(isTextContainUpperCase(IndexName)){
return "Index name should be in lowercase";
}
else if(logic to check the deployment)
{
return "Elasticsearch deployment is not reachable";
}
IndexRequest indexRequest = new IndexRequest(IndexName);
indexRequest.id(document.getId());
indexRequest.source(convertProfileDocumentToMap(document), XContentType.JSON);
IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT);
return indexResponse.getResult().name();
}
有人能帮我在上面的代码中实现这一点吗?提前谢谢
# 1 楼答案
# 2 楼答案
由于您只询问了有关检查状态的问题,我假设您可以访问
RestHighLevelClient
实例祝你好运