Search code examples
elasticsearchexchangewebserviceselasticsearch-jest

How to get creation time of indices in elastic search using Jest


I am trying to delete the indexes from elasticsearch which are created 24 hours before. I am not finding a way to get the creation time of indices for the particular node. Using spring boot elastic search, this can be accomplished. However, I am using the Jest API.


Solution

  • You can get the settings.index.creation_date value that was stored at index creation time.

    With curl you can get it easily using:

    curl -XGET localhost:9200/your_index/_settings
    

    You get:

    {
      "your_index" : {
        "settings" : {
          "index" : {
            "creation_date" : "1460663685415",   <--- this is what you're looking for
            "number_of_shards" : "5",
            "number_of_replicas" : "1",
            "version" : {
              "created" : "1040599"
            },
            "uuid" : "dIG5GYsMTueOwONu4RGSQw"
          }
        }
      }
    }
    

    With Jest, you can get the same value using:

        import io.searchbox.indices.settings.GetSettings;
    
        GetSettings getSettings = new GetSettings.Builder().build();
        JestResult result = client.execute(getSettings);
    

    You can then use JestResult in order to find the creation_date

    If I may suggest something, curator would be a much handier tool for achieving what you need.

    Simply run this once a day:

    curator delete indices --older-than 1 --time-unit days