简体   繁体   English

如何找到Elasticsearch 6.2.1中存在的索引?

[英]How to find index exists in elasticsearch 6.2.1?

I had trying to check whether a index exists in the RestHighLevelClient of elasticsearch 6.2.1 我试图检查elasticsearch 6.2.1的RestHighLevelClient中是否存在索引

presently I am using using following code 目前我正在使用以下代码

    try {

        OpenIndexRequest openIndexRequest = new OpenIndexRequest(indexName);
        client.indices().open(openIndexRequest, header).isAcknowledged();

    } catch (ElasticsearchStatusException ex) {
        String m = "Elasticsearch exception [type=index_not_found_exception, reason=no such index]";

        if (m.equals(ex.getMessage())) {
            //TODO In case index does not exists
        }
    }

it works fine but I want to find some relevant methods like 它工作正常,但我想找到一些相关方法,例如

client.indices().exists(indexname);

elastic search 6.2.1 弹性搜索6.2.1

Any help is really appreciated. 任何帮助都非常感谢。

Until this is supported by the high-level REST client (probably as of 6.3), you can achieve this by using the low-level REST client and issuing a HEAD HTTP request to your index name 在高级REST客户端(可能从6.3开始)支持此功能之前,您可以通过使用低级REST客户端并向您的索引名称发出HEAD HTTP请求来实现此目的。

Response response = restClient.performRequest("HEAD", "/" + indexname); 
int statusCode = response.getStatusLine().getStatusCode(); 
if (statusCode == 404) {
   // index does not exist
} else {
   // index exists
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM