ElasticSearch index exists not working / reliable

前端 未结 5 1557
攒了一身酷
攒了一身酷 2021-02-19 09:41

I am writing a simple Java wrapper around ElasticSearch\'s admin client. To test it I have a main method that first checks if an index exists (IndicesExistsRequest), if so delet

5条回答
  •  长情又很酷
    2021-02-19 10:27

    Here is my solution when using RestHighLevelClient client;

    Here a code-snippet: :

    public boolean checkIfIndexExists(String indexName) throws IOException {
                Response response = client.getLowLevelClient().performRequest("HEAD", "/" + indexName);
                int statusCode = response.getStatusLine().getStatusCode(); 
                return (statusCode != 404);
        }
    

    A contribution for someone else !

提交回复
热议问题