I have a need to query the latest index that is created on Elasticsearch.
I have formed the below curl command
curl -X GET "localhost/_cat/indices?h=i,creation.date.string"
It is returning the response as follows:
accounting 2020-03-03T02:46:29.285Z
kibana_1 2020-03-02T00:58:14.386Z
Is there any way I can return this in a JSON format? I have been trying this and couldn't get a JSON response.
It is indeed possible to return the response from the _cat
API in JSON. It is also possible to sort the results by creation.date.string
.
Try this and the first element from the resulting array will be the last create index.
curl -H "Content-type: application/json" -X GET "localhost/_cat/indices?h=i,creation.date.string&format=json&s=creation.date.string:desc"