Elastic Search

Elasticsearch Show Index Creation Time

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:

curl -XGET "http://localhost:9200/_cat/indices/netflix?v" -H "kbn-xsrf: reporting"

 
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:

curl -XGET "http://localhost:9200/_cat/indices/netflix?h=index,store.size&v" -H "kbn-xsrf: reporting"

 
This should return:

index   store.size
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:

curl -XGET "http://localhost:9200/_cat/indices/netflix?h=index,creation.date&v" -H "kbn-xsrf: reporting"

 
The query above should have the index name and the creation date as shown:

index   creation.date
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:

curl -XGET "http://localhost:9200cat/indices/netflix?h=index,creation.date.string&v" -H "kbn-xsrf: reporting"

 
The resulting output is as shown:

index   creation.date.string
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.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list