Elasticsearch with dynamic data

I'd like to use Elasticsearch as a cache for our group service. It will replace an LDAP cache. I've done some experiments and it seems to be as responsive as the LDAPs. However, the data are quite dynamic--memberships change often. Is there a way for indexes to automatically recover space from deleted documents? Or is there a way to rebuild indexes without taking the service offline? It has to be up all the time.

Hi @fox

Yes you can use _reindex to copy your data and move the alias.

Let's say you have your index ldap_cache_2019_08_01 with the alias ldap_cache.
You can have a cron task that run daily when your traffic is low that will reindex your data to a new index ldap_cache_2019_08_02 then when it's done you remove the alias on the old index and add it on the new one. Then you drop the old index.
For sure you need to check before that all the data are correctly reindexed, for example you can make a count and expect to have the same number of result in both index. And reindex don't return error. :sweat_smile:
Depend on the number of update you have on your index you can run it one time a week or a month.
You can check how much delete document you have in your index and if it reach for example 10% after one month you can set your cron to reindex monthly.