Created
November 23, 2017 10:14
-
-
Save Sam-Martin/912a2a9a141bb48b0f01657265d6412d to your computer and use it in GitHub Desktop.
Remove-OldbeatsIndices.ps1
This file contains hidden or 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
$ElasticSearchURL = 'https://<elasticsearchurl>:<port>' | |
$indices = (iwr "$ElasticSearchURL/_cat/indices?format=json&pretty").content | ConvertFrom-Json | |
$indices.Index | ?{$_ -match '\d{4}\.\d\d\.\d\d$'} | sort | |
$IndicesWithDate = $indices | ?{$_.index -like '*beat-*'} | select index,@{L="Date";E={get-date ($_.index -split '-')[1]}} | |
$indicesToDelete = $IndicesWithDate | ?{$_.date -lt (Get-Date).AddDays(-7)} | |
foreach($index in $indicesToDelete){ | |
$index.index | |
iwr "$ElasticSearchURL/$($index.index)" -Method delete | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment