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

2020-12-04 15:38:52 +08:00
 nekoneko

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

_statsHighLevelClient里面有没有对应操作

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

highLevel 里面没有,直接用 lowlevel 去拿了
nekoneko
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
2020-12-04 18:06:14 +08:00
curl -XGET 'localhsot:9200/_cat/indices?v' | awk '{print $3" ==> "$7}'

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/732145

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX