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

本文涉及的产品
检索分析服务 Elasticsearch 版,2核4GB开发者规格 1个月
简介: Elasticsearch索引监控之Indices Segments API与Indices Shard Stores

本文将继续介绍elasticsearch索引监控之Indices segments与Indices Shard stores api。


image.png

提供Lucene索引(分片级别)使用的segments(段信息)。


其对应的示例代码如下:

1public static final void test_Indices_segments() {
 2        TransportClient client = EsClient.getTransportClient();
 3        try {
 4            IndicesSegmentsRequest request = new IndicesSegmentsRequest();
 5            request.indices("logs_write");
 6            ActionFuture<IndicesSegmentResponse> responseFuture = client.admin().indices().segments(request);
 7            IndicesSegmentResponse response = responseFuture.get();
 8            System.out.println(response);
 9        } catch (Throwable e) {
10            e.printStackTrace();
11        } finally {
12            EsClient.close(client);
13        }
14}

返回结果类似:

1{
 2  "_shards": ...
 3  "indices": {
 4    "test": {
 5      "shards": {
 6        "0": [
 7          {
 8            "routing": {
 9              "state": "STARTED",
10              "primary": true,
11              "node": "zDC_RorJQCao9xf9pg3Fvw"
12            },
13            "num_committed_segments": 0,
14            "num_search_segments": 1,
15            "segments": {
16              "_0": {
17                "generation": 0,
18                "num_docs": 1,
19                "deleted_docs": 0,
20                "size_in_bytes": 3800,
21                "memory_in_bytes": 1410,
22                "committed": false,
23                "search": true,
24                "version": "7.0.0",
25                "compound": true,
26                "attributes": {
27                }
28              }
29            }
30          }
31        ]
32      }
33    }
34  }
35}

返回结果字段说明如下:


  • _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默认,将输出一些调试信息,其返回结果如下:


1{
 2        "_0": {
 3
 4            "ram_tree": [
 5                {
 6                    "description": "postings [PerFieldPostings(format=1)]",
 7                    "size_in_bytes": 2696,
 8                    "children": [
 9                        {
10                            "description": "format 'Lucene50_0' ...",
11                            "size_in_bytes": 2608,
12                            "children" :[ ... ]
13                        },
14                    ]
15                },
16                ]
17        }
18}


image.png

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


对应的JAVA示例如下:

1public static final void test_Indices_Shard_Stores() {
 2   TransportClient client = EsClient.getTransportClient();
 3   try {
 4      IndicesShardStoresRequest request = new IndicesShardStoresRequest();
 5      request.indices("logs_write");
 6      ActionFuture<IndicesShardStoresResponse> responseFuture = client.admin().indices().shardStores(request);
 7      IndicesShardStoresResponse response = responseFuture.get();
 8      ImmutableOpenMap<String, ImmutableOpenIntMap<List<IndicesShardStoresResponse.StoreStatus>>> data =  response.getStoreStatuses();
 9      List indexList = new ArrayList();
10      for (Iterator it = data.keysIt(); it.hasNext(); ) {
11         String key = (String)it.next();
12         Map indexData = new HashMap();
13         indexList.add(indexData);
14         List indexShardList = new ArrayList();
15         indexData.put(key, indexShardList);
16         ImmutableOpenIntMap<List<IndicesShardStoresResponse.StoreStatus>> value = data.get(key);
17         for(Iterator it2 = value.keysIt(); it2.hasNext(); ) {
18            Integer key2 = (Integer)it2.next();
19            Map shardData = new HashMap();
20            indexShardList.add(shardData);
21            List shardStoreStatusList = new ArrayList();
22            shardData.put(key2 + "", shardStoreStatusList);
23            List<IndicesShardStoresResponse.StoreStatus> storeStatusList = value.get(key2);
24            for(IndicesShardStoresResponse.StoreStatus storeStatus : storeStatusList) {
25               Map storeStatusMap = new HashMap();
26               shardStoreStatusList.add(storeStatusMap);
27               storeStatusMap.put("allocationId", storeStatus.getAllocationId());
28               storeStatusMap.put("allocationStatus", storeStatus.getAllocationStatus().value());
29               Map discoveryNodeData = new HashMap();
30               storeStatusMap.put("discoveryNode", discoveryNodeData);
31               DiscoveryNode node = storeStatus.getNode();
32               discoveryNodeData.put("name", node.getName());
33               discoveryNodeData.put("name", node.getAddress());
34               discoveryNodeData.put("attributes", node.getAttributes());
35               discoveryNodeData.put("ephemeralId", node.getEphemeralId());
36               discoveryNodeData.put("hostAddress", node.getHostAddress());
37               discoveryNodeData.put("hostName", node.getHostName());
38               discoveryNodeData.put("id", node.getId());
39               discoveryNodeData.put("roles", node.getRoles());
40            }
41         }
42      }
43      System.out.println(FastJsonUtils.getBeanToJson(indexList));
44   } catch (Throwable e) {
45      e.printStackTrace();
46   } finally {
47      EsClient.close(client);
48   }
49}

返回的结果为:

1[
 2    {
 3        "logs-000002":[
 4        {
 5            0:[    // @1
 6                    {
 7                        "discoveryNode":{   // @2
 8                            "hostName":"127.0.0.1",
 9                            "roles":[
10                                "MASTER",
11                                "DATA",
12                                "INGEST"
13                            ],
14                            "name":{
15                                "address":"127.0.0.1",
16                                "fragment":true,
17                                "port":9300
18                            },
19                            "attributes":{
20                                "ml.machine_memory":"16964890624",
21                                "ml.max_open_jobs":"20",
22                                "xpack.installed":"true",
23                                "ml.enabled":"true"
24                            },
25                            "hostAddress":"127.0.0.1",
26                            "id":"ekEDWaVVRH-944BgEsfRLA",
27                            "ephemeralId":"ox0CP9hhQOu1klZgNv7Ezw"
28                        },
29                        "allocationId":"KRw3BYPFTrK39HOYXzwXBA",      // @3
30                        "allocationStatus":"primary"                                      // @4
31                    }
32                ]
33            }
34
35            //由于当前试验环境为单机模式,故省略其他分片信息
36
37        ]
38    }
39]

代码@1:分片编号。


代码@2:分片所在的节点的信息,包含名称、角色、id、地址等信息。


代码@3:副本的分配ID。


代码@4:分配的状态,其值为primary、replica、unused。


索引监控相关API就介绍到这里了。

相关实践学习
使用阿里云Elasticsearch体验信息检索加速
通过创建登录阿里云Elasticsearch集群,使用DataWorks将MySQL数据同步至Elasticsearch,体验多条件检索效果,简单展示数据同步和信息检索加速的过程和操作。
ElasticSearch 入门精讲
ElasticSearch是一个开源的、基于Lucene的、分布式、高扩展、高实时的搜索与数据分析引擎。根据DB-Engines的排名显示,Elasticsearch是最受欢迎的企业搜索引擎,其次是Apache Solr(也是基于Lucene)。 ElasticSearch的实现原理主要分为以下几个步骤: 用户将数据提交到Elastic Search 数据库中 通过分词控制器去将对应的语句分词,将其权重和分词结果一并存入数据 当用户搜索数据时候,再根据权重将结果排名、打分 将返回结果呈现给用户 Elasticsearch可以用于搜索各种文档。它提供可扩展的搜索,具有接近实时的搜索,并支持多租户。
相关文章
|
2月前
|
存储 API 数据库
检索服务elasticsearch索引(Index)
【8月更文挑战第23天】
46 6
|
22天前
|
JSON 自然语言处理 数据库
ElasticSearch基础1——索引和文档。Kibana,RestClient操作索引和文档+黑马旅游ES库导入
概念、ik分词器、倒排索引、索引和文档的增删改查、RestClient对索引和文档的增删改查
ElasticSearch基础1——索引和文档。Kibana,RestClient操作索引和文档+黑马旅游ES库导入
|
1月前
|
存储 搜索推荐 数据建模
Elasticsearch 的数据建模与索引设计
【9月更文第3天】Elasticsearch 是一个基于 Lucene 的搜索引擎,广泛应用于全文检索、数据分析等领域。为了确保 Elasticsearch 的高效运行,合理的数据建模和索引设计至关重要。本文将探讨如何为不同的应用场景设计高效的索引结构,并分享一些数据建模的最佳实践。
54 2
|
2月前
|
存储 运维 搜索推荐
运维开发.索引引擎ElasticSearch.倒序索引的概念
运维开发.索引引擎ElasticSearch.倒序索引的概念
42 1
|
2月前
|
缓存 监控 NoSQL
【Azure Redis 缓存】Redis的监控方式? 是否有API接口调用来获取监控值
【Azure Redis 缓存】Redis的监控方式? 是否有API接口调用来获取监控值
|
2月前
|
JSON 自然语言处理 数据库
Elasticsearch从入门到项目部署 安装 分词器 索引库操作
这篇文章详细介绍了Elasticsearch的基本概念、倒排索引原理、安装部署、IK分词器的使用,以及如何在Elasticsearch中进行索引库的CRUD操作,旨在帮助读者从入门到项目部署全面掌握Elasticsearch的使用。
|
2月前
|
自然语言处理 Java 索引
ElasticSearch 实现分词全文检索 - Java SpringBoot ES 索引操作
ElasticSearch 实现分词全文检索 - Java SpringBoot ES 索引操作
34 0
|
2月前
|
机器人 API Python
智能对话机器人(通义版)会话接口API使用Quick Start
本文主要演示了如何使用python脚本快速调用智能对话机器人API接口,在参数获取的部分给出了具体的获取位置截图,这部分容易出错,第一次使用务必仔细参考接入参数获取的位置。
121 1
|
12天前
|
安全 API 开发者
Web 开发新风尚!Python RESTful API 设计与实现,让你的接口更懂开发者心!
在当前的Web开发中,Python因能构建高效简洁的RESTful API而备受青睐,大大提升了开发效率和用户体验。本文将介绍RESTful API的基本原则及其在Python中的实现方法。以Flask为例,演示了如何通过不同的HTTP方法(如GET、POST、PUT、DELETE)来创建、读取、更新和删除用户信息。此示例还包括了基本的路由设置及操作,为开发者提供了清晰的API交互指南。
55 6
|
2月前
|
存储 JSON API
淘系API接口(解析返回的json数据)商品详情数据解析助力开发者
——在成长的路上,我们都是同行者。这篇关于商品详情API接口的文章,希望能帮助到您。期待与您继续分享更多API接口的知识,请记得关注Anzexi58哦! 淘宝API接口(如淘宝开放平台提供的API)允许开发者获取淘宝商品的各种信息,包括商品详情。然而,需要注意的是,直接访问淘宝的商品数据API通常需要商家身份或开发者权限,并且需要遵循淘宝的API使用协议。
淘系API接口(解析返回的json数据)商品详情数据解析助力开发者
下一篇
无影云桌面