您当前的位置: 首页 > 

qq_34412985

暂无认证

  • 0浏览

    0关注

    1061博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

RestHighLevelClient判断index是否存在

qq_34412985 发布时间:2020-02-17 20:55:41 ,浏览量:0

判断Index是否存在版本以6.4.2为准,6.2.1api不一样

    public boolean indexExists(String indexName) {             GetIndexRequest request = new GetIndexRequest();             request.indices(indexName);             try {                 return rhlClient.indices().exists(request, RequestOptions.DEFAULT);             } catch (IOException e) {                 e.printStackTrace();                 return false;             }         }

6.2.1api使用以下方法,通过异常捕获判断es_not_found_exception

public boolean isExistIndex(String indexName){      OpenIndexRequest openIndexRequest = new OpenIndexRequest(indexName);     /*IndicesExistsRequest request = new IndicesExistsRequest(indexName);      GetIndexRequest request = new GetIndexRequest();     org.elasticsearch.client.Client Client=client;     IndicesExistsResponse response = Client.admin().indices().exists(request).actionGet();     if (response.isExists()) {         return true;     }     return false;*/      try {           client.indices().open(openIndexRequest);           return true;      }catch (ElasticsearchException e) {          return false;      }catch (Exception e) {         return false;     }  }

 

关注
打赏
1653291990
查看更多评论
立即登录/注册

微信扫码登录

0.0374s