弹性搜索cat索引为JSON格式

编程入门 行业动态 更新时间:2024-10-10 19:21:46
本文介绍了弹性搜索cat索引为JSON格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

使用Elasticsearch 1.7,我想以JSON格式查看 _cat / indices 的结果。我了解结果旨在对齐/漂亮/可读,但是有没有办法使用Elasticsearch API将其转换为JSON?

解决方案

每 cat API的文档:

JSON是伟大的...对于电脑。即使它是漂亮的打印,试图找到数据中的关系是乏味的。人的眼睛,特别是当看着一个ssh终端,需要紧凑和对齐的文本。 cat API旨在满足这一需求。

换句话说,cat API旨在以此格式提供数据。所以你将要使用不同形式的API。问题是(至少这是我的问题),谷歌搜索弹性搜索列表索引提出了猫API作为第一个结果,所以这个问题是非常合理的。

要获取JSON格式的所有索引,就像运行这样一样简单:

GET / * / _ stats

这是很多数据。你可能想要JSON,因为你想对它进行某种处理。回到我如何发现这个问题,我实际上想要获得按商店大小排序的索引列表,我不想使用 curl 和 sort unix命令这样做。该命令如下所示:

GET / * / _ stats / store pre>

不幸的是,搜索体中的排序将不适用于 _stats 命令(至少我无法使其工作)。但是,添加存储属性将使您只收回有关每个索引的数据存储的信息。

有关指标属性的详细信息,请参见 _stats文档。

Using Elasticsearch 1.7, I want to see the results of _cat/indices in JSON format. I understand the results are meant to be aligned/pretty/readable, but is there a way to convert it to JSON using Elasticsearch API?

解决方案

Per the documentation of cat APIs:

JSON is great… for computers. Even if it’s pretty-printed, trying to find relationships in the data is tedious. Human eyes, especially when looking at an ssh terminal, need compact and aligned text. The cat API aims to meet this need.

In other words, the cat API is designed to give data in this format. So you will want to use a different form of the API. The problem is (at least this was my problem) that googling "elasticsearch list indices" brings up the cat API as the first result, so this question is pretty reasonable.

To get all of the indices in JSON form, it's as easy as running this:

GET /*/_stats

That's a lot of data though. You likely want JSON because you want to do some sort of processing on it. Going back to how I found this question, I actually wanted to get a list of indices sorted by the store size and I didn't want to have to use curl and sort unix commands to do so. That command looks like this:

GET /*/_stats/store

Unfortunately, the sort in the search body won't work for the _stats command (at least, I haven't been able to make it work). But adding the store attribute will make it so you only get back the information about the data stores for each index.

More information about the metrics attributes can be found in the _stats documentation.

更多推荐

弹性搜索cat索引为JSON格式

本文发布于:2023-11-24 23:37:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627373.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:弹性   索引   格式   cat   JSON

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!