I have a versioned index in Elasticsearch where I'm storing the document whenever a modification is made to it. After running it for some time I've realised that storing all the versions of a document is taking a lot of disk space. I don't have any version field instead I use a date field in order to see the latest version and the one previous to it.
I just want to keep the last two versions. But I'm unable to figure out a way to delete the previous versions.
Is there any way to do it?
Periodically run a deletion of all documents ordered by date, from the latest to the oldest, starting from 2 ?
where INDEX is your index, and DATE the name of your date field.
Note: the 'from' parameter has been removed in Elasticsearch 8.x.