Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch cat indices in JSON format

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?

like image 653
chevin99 Avatar asked Sep 03 '25 15:09

chevin99


2 Answers

Append format param, eg: _cat/indices?format=json

You can also make it pretty-formatted with: _cat/indices?format=json&pretty=true

like image 171
matt burns Avatar answered Sep 05 '25 15:09

matt burns


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.

like image 25
Matt Dodge Avatar answered Sep 05 '25 14:09

Matt Dodge