栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

Elasticsearch索引检控之Indices Segments API与Indices Shard Stores

Elasticsearch索引检控之Indices Segments API与Indices Shard Stores

TransportClient client = EsClient.getTransportClient();

try {

IndicesSegmentsRequest request = new IndicesSegmentsRequest();

request.indices(“logs_write”);

ActionFuture responseFuture = client.admin().indices().segments(request);

IndicesSegmentResponse response = responseFuture.get();

System.out.println(response);

} catch (Throwable e) {

e.printStackTrace();

} finally {

EsClient.close(client);

}

}

返回结果类似:

{

“_shards”: …

“indices”: {

“test”: {

“shards”: {

“0”: [

{

“routing”: {

“state”: “STARTED”,

“primary”: true,

“node”: “zDC_RorJQCao9xf9pg3Fvw”

},

“num_committed_segments”: 0,

“num_search_segments”: 1,

“segments”: {

“_0”: {

“generation”: 0,

“num_docs”: 1,

“deleted_docs”: 0,

“size_in_bytes”: 3800,

“memory_in_bytes”: 1410,

“committed”: false,

“search”: true,

“version”: “7.0.0”,

“compound”: true,

“attributes”: {

}

}

}

}

]

}

}

}

}

返回结果字段说明如下:

  • _0

段的名称,表示第一个段。

  • generation

在需要编写新段时基本上递增的生成数。段名是从这个生成号派生出来的。

  • num_docs

存储在此段中的未删除文档的数量。

  • deleted_docs

存储在此段中的已删除文档的数量。如果这个数大于0,那么当这个段合并时,空间就会被回收。

  • size_in_bytes

段使用的磁盘空间量,以字节为单位。

  • memory_in_bytes

段存储在内存中的字节数,如果-1表示elasticsearch无法计算。

  • committed

段是否已在磁盘上同步(是否已经提交到磁盘)。

  • search

是否可搜索,如果为false,表示段已提交到磁盘,但还没有被refresh,故暂时不可用来搜索。

  • version

底层使用的lucene版本。

  • compound

段是否存储在复合文件中。当为true时,这意味着Lucene将该段中的所有文件合并为一个文件,以便保存文件描述符。

  • attributes

其他属性。

另外Indices Segments支持verbose默认,将输出一些调试信息,其返回结果如下:

{

“_0”: {

“ram_tree”: [

{

“description”: “postings [PerFieldPostings(format=1)]”,

“size_in_bytes”: 2696,

“children”: [

{

“description”: “format ‘Lucene50_0’ …”,

“size_in_bytes”: 2608,

“children” :[ … ]

},

]

},

]

}

}

2、Indices Shard Stores

主要展示索引分片副本的存储信息。默认情况下,列表只存储至少有一个未分配副本的分片的信息。当集群健康状态为黄色时,将列出至少有一个未分配副本的分片的存储信息。当集群健康状态为红色时,这将列出具有未分配初选的碎片的存储信息。

对应的JAVA示例如下:

public static final void test_Indices_Shard_Stores() {

TransportClient client = EsClient.getTransportClient();

try {

IndicesShardStoresRequest request = new IndicesShardStoresRequest();

request.indices(“logs_write”);

ActionFuture responseFuture = client.admin().indices().shardStores(request);

IndicesShardStoresResponse response = responseFuture.get();

ImmutableOpenMap>> data = response.getStoreStatuses();

List indexList = new ArrayList();

for (Iterator it = data.keysIt(); it.hasNext(); ) {

String key = (String)it.next();

Map indexData = new HashMap();

indexList.add(indexData);

List indexShardList = new ArrayList();

indexData.put(key, indexShardList);

ImmutableOpenIntMap> value = data.get(key);

for(Iterator it2 = value.keysIt(); it2.hasNext(); ) {

Integer key2 = (Integer)it2.next();

Map shardData = new HashMap();

indexShardList.add(shardData);

List shardStoreStatusList = new ArrayList();

shardData.put(key2 + “”, shardStoreStatusList);

List storeStatusList = value.get(key2);

for(IndicesShardStoresResponse.StoreStatus storeStatus : storeStatusList) {

Map storeStatusMap = new HashMap();

shardStoreStatusList.add(storeStatusMap);

storeStatusMap.put(“allocationId”, storeStatus.getAllocati

《一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》

【docs.qq.com/doc/DSmxTbFJ1cmN1R2dB】 完整内容开源分享

onId());

storeStatusMap.put(“allocationStatus”, storeStatus.getAllocationStatus().value());

Map discoveryNodeData = new HashMap();

storeStatusMap.put(“discoveryNode”, discoveryNodeData);

DiscoveryNode node = storeStatus.getNode();

discoveryNodeData.put(“name”, node.getName());

discoveryNodeData.put(“name”, node.getAddress());

discoveryNodeData.put(“attributes”, node.getAttributes());

discoveryNodeData.put(“ephemeralId”, node.getEphemeralId());

discoveryNodeData.put(“hostAddress”, node.getHostAddress());

discoveryNodeData.put(“hostName”, node.getHostName());

discoveryNodeData.put(“id”, node.getId());

discoveryNodeData.put(“roles”, node.getRoles());

}

}

}

System.out.println(FastJsonUtils.getBeanToJson(indexList));

} catch (Throwable e) {

e.printStackTrace();

} finally {

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/671733.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号