Keep indices closed by default

Hi everyone !

I am facing a little issue with the embedded elasticsearch server my application is using, and I think you might be able to help me.

The stage of my application is, basically, to be able to download MySQL databases and store them offline to make ultra-fast requests once the server is loaded.
However, the problem is that the server opens every stored index by default, which means the more databases I have downloaded, the longer it takes to load.

That is why I have set up a solution allowing to open an index, if existing, only when a request on that database is made. However, my issue is that when it comes to that point, all of the indexes have already been opened since this is the first step that is made after the creation of the embedded ES server.

So I was wondering :

  • Does my solution seem right ?
  • If it does so, how could I prevent the server from automatically opening all the indices ? I guess an option in the elasticsearch.yml file would be perfect, but I could not find it...

By the way, I forgot to specify that my program and all my requests are made with the Java API.

I hope my issue was clear enough and someone will be able to help me.
By advance, thank you !

I suspect you can just close them when you are done with them and reopen them when you need them. Elasticsearch doesn't have any autoclosing stuff that I know of. You could write an autoclosing thing as a cron-like job that checks the indices stats api every few minutes and looks for indices that haven't had any searches in X minutes. If they haven't you can close them. I guess.

This is all predicated on my assumption that if you close an Elasticsearch index it'll stay closed after a restart. If that doesn't work I think that is a bug.

that shud work... one thing u shud keep in mind... the larger the size of ur indices the more they will take time to be initialized when u open next...

You're correct.

ES cannot auto open or close an index, you need to explicitly tell it.

Huge thanks for the tips !

Indeed, closed indices remain closed at restart, so closing them after a certain time of inactivity, as you suggested, solved my issue !