首页 > 解决方案 > 检查弹性搜索部署当前是否可用或未使用 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();

    }

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

标签: javaspring-bootelasticsearch

解决方案


  1. 创建一个休息客户端并考虑使用嗅探器以实现连接故障转移
  2. 检查集群是否准备就绪
  3. 检查索引是否存在
  4. 如果没有则初始化索引(使用索引 api

推荐阅读