Skip to content

Instantly share code, notes, and snippets.

@tjrobinson
Created May 14, 2015 08:05
Show Gist options
  • Save tjrobinson/4bfa27542fdaa5595b0f to your computer and use it in GitHub Desktop.
Save tjrobinson/4bfa27542fdaa5595b0f to your computer and use it in GitHub Desktop.
es-curator.ps1
# 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