ElasticSearch index exists not working / reliable

前端 未结 5 1563
攒了一身酷
攒了一身酷 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:19

    The skgemini's answer is ok if you want to check if index is available by the actual index name or any of its aliases.

    If you however want to check only by the index name, here is how.

    public boolean checkIfIndexExists(String index) {
    
        IndexMetaData indexMetaData = client.admin().cluster()
                .state(Requests.clusterStateRequest())
                .actionGet()
                .getState()
                .getMetaData()
                .index(index);
    
        return (indexMetaData != null);
    
    }
    

提交回复
热议问题