V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
nekoneko
V2EX  ›  Elasticsearch

一个关于 ES 的问题,和_stats 这个接口有关

  •  1
     
  •   nekoneko · 2020-12-04 15:38:52 +08:00 · 1962 次点击
    这是一个创建于 1210 天前的主题,其中的信息可能已经有所发展或是发生改变。

    有一个需求是返回当前所有 index 及其对应的文档数量,
    发现 _stats 接口可以可以做到
    但是目前没找到在 RestHighLevelClient 中对应的操作

    • 既然我已诚心诚意得发问了
    • 有没有谁大发慈悲告诉我
    • 为了防止世界被破坏
    • 为了守护世界的和平

    _statsHighLevelClient里面有没有对应操作

    11 条回复    2020-12-04 18:06:14 +08:00
    rrfeng
        1
    rrfeng  
       2020-12-04 15:51:25 +08:00 via Android
    这属于管理接口,找找看有没有 admin client 之类的玩意
    chendy
        2
    chendy  
       2020-12-04 16:02:23 +08:00
    如果只是要获取文档数量的话
    发一个没有条件,size=0 的 search,取 hits,满足需求么?
    fantastM
        4
    fantastM  
       2020-12-04 16:16:43 +08:00
    看来老哥也是个宝可梦粉
    nekoneko
        5
    nekoneko  
    OP
       2020-12-04 16:17:11 +08:00
    @z657386160z #3 这个试了,不是这个
    nekoneko
        6
    nekoneko  
    OP
       2020-12-04 16:18:08 +08:00
    @chendy #2 现在是这样取的,但是我有 500 个 index 的话就得循环 500 次请求...
    chendy
        7
    chendy  
       2020-12-04 16:27:21 +08:00
    @nekoneko #6 index 名字传个 * 就是所有 index 了
    nekoneko
        8
    nekoneko  
    OP
       2020-12-04 16:40:03 +08:00
    @chendy #7 辣个查出来是所有 index 加起来的,我想查每个索引对应的文档数量
    nekoneko
        9
    nekoneko  
    OP
       2020-12-04 17:17:25 +08:00   ❤️ 1
    @rrfeng #1
    @chendy #2
    @z657386160z #3

    highLevel 里面没有,直接用 lowlevel 去拿了
    nekoneko
        10
    nekoneko  
    OP
       2020-12-04 17:48:29 +08:00
    ```
    RestClient lowLevelClient = client.getLowLevelClient();
    Request request = new Request("GET", "/_stats");
    Response response = lowLevelClient.performRequest(request);
    HttpEntity entity = response.getEntity();
    InputStream content = entity.getContent();
    HashMap responseMap = objectMapper.readValue(content, HashMap.class);
    ```
    RudyS
        11
    RudyS  
       2020-12-04 18:06:14 +08:00
    curl -XGET 'localhsot:9200/_cat/indices?v' | awk '{print $3" ==> "$7}'
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3236 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 12:09 · PVG 20:09 · LAX 05:09 · JFK 08:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.