V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
nekoneko
18.39D

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

  •  1
     
  •   nekoneko · Dec 4, 2020 · 5270 views
    This topic created in 1983 days ago, the information mentioned may be changed or developed.

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

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

    _statsHighLevelClient里面有没有对应操作

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

    highLevel 里面没有,直接用 lowlevel 去拿了
    nekoneko
        10
    nekoneko  
    OP
       Dec 4, 2020
    ```
    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);
    ```
    randomuuid
        11
    randomuuid  
       Dec 4, 2020
    curl -XGET 'localhsot:9200/_cat/indices?v' | awk '{print $3" ==> "$7}'
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4069 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 73ms · UTC 04:18 · PVG 12:18 · LAX 21:18 · JFK 00:18
    ♥ Do have faith in what you're doing.