When managing an Elasticsearch cluster, you may need to determine the actual creation time of a given index. You can then use this information to gather details such as the changes to the cluster after and before the creation of the index, fetching other indices using the creation time, and etc.
In this brief tutorial, you will discover how to fetch a specific index’s creation time using the CAT Index API.
Cat Index API
The cat index API lets us fetch information about a given index in the cluster. It is a valuable API in Elasticsearch as it allows you to fetch index information without performance overhead quickly. However, do not use this API in applications. It is built for quick console performance.
For example, to fetch the information about the ‘Netflix; index, we can run the query:
The above request should return information as shown:
We can use the ?h parameter to specify the columns we wish to retrieve from the API. For example, to get the index name and the store size, we can run the query:
This should return:
netflix 9.8mb
Elasticsearch Fetch Index Creation Time
We can pass the creation.date column to the h parameter to get the creation time of an index. This should retrieve the creation.date column as shown in the example below:
The query above should have the index name and the creation date as shown:
netflix 1662088586861
Note that the resulting creation time is a Unix-Timestamp. You can use a tool such as Epoch to UTC to convert it into a human-readable format.
You can also fetch the creation.date.string to fetch the human-readable format of the index creation time.
Example:
The resulting output is as shown:
netflix 2022-09-02T03:16:26.861Z
Conclusion
In this post, you discovered how you could retrieve the creation time of a given index using the cat index API.