Skip to content

Instantly share code, notes, and snippets.

@AndyPook
Created March 9, 2016 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndyPook/cedc61cb5e361d631ea2 to your computer and use it in GitHub Desktop.
Save AndyPook/cedc61cb5e361d631ea2 to your computer and use it in GitHub Desktop.
very simple powershell script to delete older logstash indexes
# get indexes in "logstash" alias
$indexes = Invoke-RestMethod "http://eshost: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
# "Substring(9)" returns the date part of "logstash-yyyy-mm-dd"
$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://eshost:9200/$_"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment