3

When I delete documents from Elasticsearch, why does my 'total size' stay the same despite obviously being far smaller with the absence of previously stored data? I've read about index optimization but I'm not sure what this is or how to do it.

Thanks

1 Answers1

9

I'm sure there are tons of questions relating to this on both SO and Google so this may be a duplicate answer. However - deleting documents only marks them as deleted, it doesn't actually remove them from your data store.

In old ES, there used to be a feature named 'optimize' (which is deprecated) - nowdays forcemerge is the enhanced replacement. The following command should free up the space you're entitled to.

curl -XPOST 'http://localhost:9200/_forcemerge?only_expunge_deletes=true'

Here's a bit more info on forcemerge if you're interested:

https://www.elastic.co/blog/found-elasticsearch-from-the-bottom-up

Alex
  • 376
  • 1
  • 17
  • 3
    Plus, the segments have to use up to a specific threshold space in order for the expunge to kick in. By default, the setting `index.merge.policy.expunge_deletes_allowed` is set at 10%, so if you have less than 10% of deleted documents, they won't get wiped. But you shouldn't really worry about that. – Val Aug 14 '17 at 13:34
  • 2
    Just out of curiosity, can you lower that percentage all the way to 1% or 0? or is there a cap @Val – Alex Aug 14 '17 at 13:39
  • 2
    You definitely can! – Val Aug 14 '17 at 13:41