ElastaticSearch java查看es索引是否存在

java查看es索引是否存在

    /**
     * 判断指定的索引名是否存在
     *
     * @param indexName 索引名
     * @return 存在:true; 不存在:false;
     */
    public static boolean isExistsIndex(String indexName) {
        //初始化client
        TransportClient client = getClient(CLUSTER_NAME, IP, PORT);
        return client.admin().indices().exists(new IndicesExistsRequest().indices(indexName)).actionGet().isExists();
    }

以上的 client,改成项目中使用的 es client即可。如果没有现成的client,也可以参考以下:

https://www.cnblogs.com/expiator/p/15735701.html

原文地址:https://www.cnblogs.com/expiator/p/15737334.html