码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Elasticsearch查询分片信息


    package com.easy.es.monitor;
    
    import com.easy.es.common.CommonUtils;
    import com.easy.es.network.HttpClientResp;
    import com.easy.es.network.HttpUtils;
    import lombok.Data;
    
    import java.io.IOException;
    import java.net.URISyntaxException;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Map;
    
    /**
     * @author a.du on 2022/10/31.
     */
    public class Shards {
        //index                                  shard prirep state      docs    store ip             node
        private static final String API = "/_cat/shards";
    
        public static List getShardInfo(String host, String port, Map params) throws IOException, URISyntaxException {
            HttpClientResp httpClientResp = HttpUtils.doGet(CommonUtils.getUrl(host, port, API), params);
            if (200 == httpClientResp.getCode()) {
                String[] result = httpClientResp.getContent().split("\n");
                List shardInfoList = new ArrayList<>();
                for (int i = 1; i < result.length; i++) {
                    ShardInfo shardInfo = new ShardInfo();
                    String[] temp = result[i].split("\\s+");
                    //10.101.129.205 12463 6.3.2 - 10.101.129.205:11463
                    shardInfo.setIndexName(temp[0]);
                    shardInfo.setShard(temp[1]);
                    shardInfo.setPrirep(temp[2]);
                    shardInfo.setState(temp[3]);
                    shardInfo.setDocs(temp[4]);
                    shardInfo.setStore(temp[5]);
                    shardInfo.setIp(temp[6]);
                    shardInfo.setNode(temp[7]);
                    shardInfoList.add(shardInfo);
                }
                return shardInfoList;
            }
            return null;
        }
    }
    
    @Data
    class ShardInfo {
        /**
         * 索引名称
         */
        private String indexName;
        /**
         * 分片编号
         */
        private String shard;
        /**
         * 主分片:p 副本分片:r
         */
        private String prirep;
        /**
         * 状态:
         * INITIALIZING: 正在恢复
         * RELOCATING: 迁移中
         * STARTED: 已启动
         * UNASSIGNED: 未分配
         */
        private String state;
        /**
         * 文档数量
         */
        private String docs;
        /**
         * 占用磁盘空间
         */
        private String store;
        /**
         * ip
         */
        private String ip;
        /**
         * 节点
         */
        private String node;
    }
    
    测试用例:
    1. public class Main {
    2. public static void main(String[] args) {
    3. Map params = new HashMap<>();
    4. params.put("index", "ocontent_20220905");
    5. System.out.println(JSON.toJSONString(Shards.getShardInfo("10.10.19.24", "1463",params)));
    6. } catch (IOException e) {
    7. e.printStackTrace();
    8. } catch (URISyntaxException e) {
    9. e.printStackTrace();
    10. }
    11. }
    12. }

  • 相关阅读:
    macOS环境使用HomeBrew安装MySQL【日常记录,可供参考】
    删数字问题 贪心算法 1472
    荧光标记氨基酸:荧光标记DL-天门冬氨酸,荧光标记甘氨酸-DL-天冬氨酸,DL aspartic acid labeled
    MFC基础-选项卡控件
    虹科Pico汽车示波器 | 免拆诊断案例 | 2016款保时捷911 GT3 RS车发动机异响
    idea + Docker-Compose 实现自动化打包部署(仅限测试环境)
    【Leetcode每日一题.784:字母大小写全排列~~~DFS深度优先遍历(递归+回溯)+BFS广度优先遍历】
    论文笔记: 图神经网络 GAT
    Qt字符串类应用与常用基本数据类型
    七、 循环
  • 原文地址:https://blog.csdn.net/duzm200542901104/article/details/127609285
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号