Reputation: 11
Does elasticsearch have an API to return the creation timestamp of an index (or sort by it)? I want to delete the oldest 'n' indexes of some "index-type" and restrict some queries to only the newest index. The naming convention that I use for indexes is something like: <indextype>_<client_hostname>_<batch_name>.
Upvotes: 1
Views: 2368
Reputation: 60205
The _timestamp
field is per document. If you retrieve the oldest document based on the _timestamp
it might help, but the index could have been previously created using the create index api. In fact, an index is by default automatically created when you index the first document into it (unless you disable this behaviour), but you can also create an index upfront.
I think I would add the timestamp to the name of the index too and manage this outside of elasticsearch. Remember that you can also close an index without deleting the data if you need to.
Upvotes: 2
Reputation: 33341
Yes, it has a _timestamp
field. It is disabled by default, though, so you will need to enable it, using a mapping such as that provided in the documentation, with: "_timestamp" : { "enabled" : true }
Upvotes: 1