没有合适的资源?快使用搜索试试~ 我知道了~
首页RestHighLevelClient判断index是否存在
判断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);
资源详情
资源评论
资源推荐

RestHighLevelClient判断判断index是否存在是否存在
判断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;
}
}
作者:qq_34412985

















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0