Elastic Search Java API 汇总

常用的elastic search java API:


获取索引列表:

  public static List<String> listIndex() {
        List<String> list = new ArrayList<>();
        GetIndexRequestBuilder builder = client.admin().indices().prepareGetIndex();
        GetIndexResponse response = builder.get();
        Collections.addAll(list, response.getIndices());
        return list;
    }

获取索引状态列表:

public Map<String, Object> getIndexState(TransportClient client) {
        Map<String, Object> indexStateMap = new HashedMap();
        List<String> indexList = new ArrayList<>();
        List<String> openIndexList = new ArrayList<>();
        List<String> closeIndexList = new ArrayList<>();
        ClusterStateResponse response = client.admin().cluster().prepareState().execute().actionGet();
        Iterator<ObjectObjectCursor<String, IndexMetaData>> indexIterator = response.getState().getMetaData().getIndices().iterator();
        while (indexIterator.hasNext()) {
            ObjectObjectCursor objectIndex = indexIterator.next();
            String index = objectIndex.key.toString();
            if (!index.contains(".")) {
                IndexMetaData indexMetaData = (IndexMetaData) objectIndex.value;
                String indexState = indexMetaData.getState().name();
                if (indexState.contains("OPEN")) {
                    openIndexList.add(index);
                } else closeIndexList.add(index);
                indexList.add(index);
            }
        }
        indexStateMap.put("indexList", indexList);
        indexStateMap.put("openIndexList", openIndexList);
        indexStateMap.put("closeIndexList", closeIndexList);
        return indexStateMap;

    }

注:关闭的索引,无法获取health状态。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值