Elasticsearch Java-Api 获取所有索引

EsConfig连接

@Component
public class EsConfig {
     
    
    public RestHighLevelClient getEsHighInit2() {
     
        RestClientBuilder http = RestClient.builder(new HttpHost("127.0.0.1", 9200, "http"))
                .setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {
     
                    @Override
                    public RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder requestConfigBuilder) {
     
                        requestConfigBuilder.setConnectTimeout(700000);
                        requestConfigBuilder.setSocketTimeout(600000);
                        requestConfigBuilder.setConnectionRequestTimeout(100000);
                        return requestConfigBuilder;
                    }
                });
        return new RestHighLevelClient(http);

    }
}

TEST测试

@org.junit.Test
public void aaaa() throws IOException {
     
        //获取es连接
        RestHighLevelClient esHighInit = esConfig.getEsHighInit2();
        List<Map<String, Object>> resultList = new ArrayList<>();
        GetAliasesRequest request = new GetAliasesRequest();
        GetAliasesResponse alias = esHighInit.indices().getAlias(request, RequestOptions.DEFAULT);
        Map<String, Set<AliasMetaData>> map = alias.getAliases();
        map.forEach((k, v) -> {
     
            if (!k.startsWith(".")) {
     //忽略elasticesearch 默认的
                Map map1 = new HashMap();
                map1.put("indexName", k);
                resultList.add(map1);
            }
        });

        System.out.println(objectMapper.writeValueAsString(resultList));
        //[{"indexName":"%{test222}"},{"indexName":"test"}]
}

推荐文章

Spring Cloud Alibaba 系列学习笔记
SpringCloud Alibaba Nacos
SpringCloud Alibaba Sentinel
@SentinelResource注解总结,异常、降级兜底
SpringCloud Alibaba Sentine 规则持久化
SpringCloud Alibaba RocketMQ
Seata1.4.2分布式事务整合nacos+SpringCloudAlibaba
2021最新Java面试题

觉得对您有帮助就留下个宝贵的吧!

你可能感兴趣的:(ELK,elasticsearch)