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?
format
param, eg: _cat/indices?format=json
You can also make it pretty-formatted with: _cat/indices?format=json&pretty=true
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With