Elasticsearch java客户端调用cat服务

时间:2024-01-03 21:45:20

开发环境,测试环境,预发环境和生产环境一般相互隔离的,使用开发环境或者测试环境可以使用cat来查看索引的情况

例如:

Elasticsearch java客户端调用cat服务

但预防环境和测试环境是不允许访问的,那怎么办呢?

可以使用后台来查看上述信息,提供界面交互。

java client如何调用cat服务呢

举例:

            Settings setting=Settings.builder().put("cluster.name", "my-cluster").build();
TransportClient client=new PreBuiltTransportClient(setting);
client.addTransportAddress(new TransportAddress(InetAddress.getByName("127.0.0.1"), 9300)); Map<String, IndexStats> stats=client.admin().indices().stats(new IndicesStatsRequest()).actionGet().getIndices();
for(IndexStats stat:stats.values()) {
System.out.println(JSON.toJSONString(stat.getTotal().getDocs()));
}

输出结果

{"averageSizeInBytes":457,"count":5966,"deleted":150,"fragment":true,"totalSizeInBytes":2798548}
{"averageSizeInBytes":389,"count":11030,"deleted":52,"fragment":true,"totalSizeInBytes":4316958}
{"averageSizeInBytes":545,"count":3516,"deleted":144,"fragment":true,"totalSizeInBytes":1996912}
{"averageSizeInBytes":5154,"count":1,"deleted":0,"fragment":true,"totalSizeInBytes":5154}
{"averageSizeInBytes":394,"count":12717,"deleted":47,"fragment":true,"totalSizeInBytes":5029512}
{"averageSizeInBytes":437,"count":347,"deleted":0,"fragment":true,"totalSizeInBytes":151761}
{"averageSizeInBytes":393,"count":14373,"deleted":147,"fragment":true,"totalSizeInBytes":5709073}
{"averageSizeInBytes":3508,"count":3,"deleted":0,"fragment":true,"totalSizeInBytes":10525}
{"averageSizeInBytes":487,"count":5374,"deleted":288,"fragment":true,"totalSizeInBytes":2762143}
{"averageSizeInBytes":4790,"count":2,"deleted":0,"fragment":true,"totalSizeInBytes":9581}
{"averageSizeInBytes":84,"count":10000,"deleted":0,"fragment":true,"totalSizeInBytes":849464}
{"averageSizeInBytes":6374,"count":1,"deleted":0,"fragment":true,"totalSizeInBytes":6374}
{"averageSizeInBytes":3862,"count":2,"deleted":0,"fragment":true,"totalSizeInBytes":7724}