Created
March 9, 2016 13:59
-
-
Save AndyPook/cedc61cb5e361d631ea2 to your computer and use it in GitHub Desktop.
very simple powershell script to delete older logstash indexes
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://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