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

简介: 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就介绍到这里了。

相关实践学习
以电商场景为例搭建AI语义搜索应用
本实验旨在通过阿里云Elasticsearch结合阿里云搜索开发工作台AI模型服务,构建一个高效、精准的语义搜索系统,模拟电商场景,深入理解AI搜索技术原理并掌握其实现过程。
ElasticSearch 最新快速入门教程
本课程由千锋教育提供。全文搜索的需求非常大。而开源的解决办法Elasricsearch(Elastic)就是一个非常好的工具。目前是全文搜索引擎的首选。本系列教程由浅入深讲解了在CentOS7系统下如何搭建ElasticSearch,如何使用Kibana实现各种方式的搜索并详细分析了搜索的原理,最后讲解了在Java应用中如何集成ElasticSearch并实现搜索。 &nbsp;
相关文章
|
6月前
|
缓存 监控 前端开发
顺企网 API 开发实战:搜索 / 详情接口从 0 到 1 落地(附 Elasticsearch 优化 + 错误速查)
企业API开发常陷参数、缓存、错误处理三大坑?本指南拆解顺企网双接口全流程,涵盖搜索优化、签名验证、限流应对,附可复用代码与错误速查表,助你2小时高效搞定开发,提升响应速度与稳定性。
|
10月前
|
人工智能 监控 Cloud Native
深度剖析电商API监控与报警:守护电商系统稳定的核心策略
电商API监控与报警是保障电商业务稳定运行的关键工具。文章从重要性、关键指标(如响应时间、成功率、错误率等)、技术工具(如日志监控、性能监控、异常检测)及实施步骤等方面详细阐述了如何构建高效的监控体系。通过案例分析,如京东的商品API实战,展示了全链路追踪与智能告警的应用价值。未来,随着AI、自动化和云原生技术的发展,电商API监控将更加智能高效,助力提升用户体验与业务效率。
|
6月前
|
XML JSON 监控
微店商品详情API助力多店铺管理和竞品监控
微店商品详情API(micro.item_get)可获取商品名称、价格、库存、图片等20余项信息,支持GET/POST请求,返回JSON或XML格式数据,适用于电商开发、库存管理与跨平台展示。
|
8月前
|
存储 缓存 监控
利用电商 API 接口,轻松完成多平台价格监控
在电商竞争中,价格策略至关重要。本文介绍如何利用电商平台API,构建自动化价格监控系统,实现多平台实时数据获取与智能调价,提升市场响应速度与销售转化率。
539 0
|
9月前
|
数据采集 监控 安全
拼多多API价格战预警:竞品监控不落人后!
在电商竞争激烈的当下,拼多多凭借低价策略迅速崛起,但也给商家带来定价挑战。本文解析如何利用API技术,构建实时价格预警与竞品监控系统,助力商家在价格战中抢占先机,实现智能调价与策略应对。
749 0
|
9月前
|
存储 数据采集 监控
电商数据分析实战:利用 API 构建商品价格监控系统
在电商运营中,商品价格直接影响转化率和竞争力。本文介绍如何构建一套自动化价格监控系统,覆盖京东、淘宝双平台,实现数据采集、存储、分析与智能告警,助力企业实时掌握价格动态,优化定价策略。
|
10月前
|
监控 供应链 数据库连接
电商API:销量监控与竞品分析利器
电商数据接口API在现代电商运营中至关重要,可实现品牌价格、销量、评论等数据监控,优化销售策略。接入主流平台如淘宝、天猫、京东等API,或使用RPA技术取数,保障数据安全与效率。通过数据库连接、ERP直连等方式整合分析数据,监控竞品与价格,掌握市场动态。同时,注重数据安全性、技术支持及成本效益,助力企业在竞争中脱颖而出,提升业务效率与竞争力。
334 0
|
存储 人工智能 API
(Elasticsearch)使用阿里云 infererence API 及 semantic text 进行向量搜索
本文展示了如何使用阿里云 infererence API 及 semantic text 进行向量搜索。
657 8
|
监控 API 索引
Elasticsearch集群使用 _cluster/health API
Elasticsearch集群使用 _cluster/health API
662 2
|
Unix API 索引
Elasticsearch集群使用 _cat/health API
Elasticsearch集群使用 _cat/health API
363 1