zoukankan      html  css  js  c++  java
  • elasticsearch判断索引是否存在

    一、判断索引是否存在 
    指定索引名,判断指定的索引是否存在集群中

    /**
         * 判断指定的索引名是否存在
         * @param indexName 索引名
         * @return  存在:true; 不存在:false;
         */
        public boolean isExistsIndex(String indexName){
            IndicesExistsResponse  response = 
                    getClient().admin().indices().exists( 
                            new IndicesExistsRequest().indices(new String[]{indexName})).actionGet();
            return response.isExists();
    }

    二、判断索引指定类型是否存在

    /**
     * 判断指定的索引的类型是否存在
     * @param indexName 索引名
     * @param indexType 索引类型
     * @return  存在:true; 不存在:false;
     */
    public boolean isExistsType(String indexName,String indexType){
        TypesExistsResponse  response = 
                getClient().admin().indices()
                .typesExists(new TypesExistsRequest(new String[]{indexName}, indexType)
                ).actionGet();
        System.out.println(FastJSONHelper.serialize(response));
        return response.isExists();
    }
    输出的JSON格式内容:
    {
        "context":{
            "empty":true
        },
        "contextEmpty":true,
        "exists":true,
        "headers":[]
    }
  • 相关阅读:
    函数总结
    python之内置函数,匿名函数
    列表推导式 生成器表达式
    迭代器和生成器函数
    最近练习题
    python----------闭包 、装饰器
    python的逻辑运算符
    python------函数嵌套及作用域链
    python ---------函数
    如何实现负载均衡
  • 原文地址:https://www.cnblogs.com/a-du/p/8807155.html
Copyright © 2011-2022 走看看