检查弹性搜索部署当前是否使用 Java



>我创建了一个用于弹性搜索 CRUD 操作的 Java 服务,我在下面给出了我的业务逻辑 我正在执行所有服务器端验证,因为我必须检查弹性搜索部署当前是否可用,在将数据插入索引之前,我必须检查弹性搜索部署当前是否可用弹性搜索的 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();
}

有人可以帮助我在上面的代码中实现这一目标吗?提前致谢

由于您只询问检查状态,因此我认为您可以访问RestHighLevelClient实例

import org.elasticsearch.client.RequestOptions;
...
public boolean checkTempConnection(RestHighLevelClient client) {
try {
return client.ping(RequestOptions.DEFAULT);
} catch (Exception e) {
log.warn("Can't get status : {}", e.getMessage());
return false; // Not available
}
}

祝你好运!

  1. 创建 REST 客户端并考虑使用嗅探器来实现连接故障转移
  2. 检查群集是否已准备就绪
  3. 检查索引是否存在
  4. 初始化索引(如果不是((使用索引 api(

相关内容

最新更新