Created
May 14, 2015 08:05
-
-
Save tjrobinson/4bfa27542fdaa5595b0f to your computer and use it in GitHub Desktop.
es-curator.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get indexes in "logstash" alias | |
$indexes = Invoke-RestMethod "http://localhost:9200/logstash/_settings" | |
# get the names of the indexes | |
$indexNames = Get-Member -InputObject $indexes -MemberType NoteProperty|%{$_.Name} | |
# foreach index check its age. If over 10 days, delete it | |
$indexNames|sort |%{ | |
$datePart = $_.Substring(9) | |
$indexAge = [datetime]::UtcNow.Date.Subtract([DateTime]::Parse($datePart)).Days | |
if($indexAge -gt 10){ | |
"Deleting $_" | |
$response = Invoke-RestMethod -method delete "http://localhost:9200/$_" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment