Skip to content

Instantly share code, notes, and snippets.

@Sam-Martin
Created November 23, 2017 10:14
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 Sam-Martin/912a2a9a141bb48b0f01657265d6412d to your computer and use it in GitHub Desktop.
Save Sam-Martin/912a2a9a141bb48b0f01657265d6412d to your computer and use it in GitHub Desktop.
Remove-OldbeatsIndices.ps1
$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