Create index at startup



I wish to create an Elasticsearch plugin, this plugin requires some information to be stored. Is there any way to create an index & its mappings at startup time?

I found this: Index Creation on Startup?
But it does not answer the question.

Thanks in advance!

(Alexander Reelsen) #2

you could use a cluster state listener and wait until the cluster is ready and then check for the existence of that index.

Note that a one time check is not enough, as you may accidentally delete that index - thus the cluster state listener makes sense.


Thank you Spinscale,

By state listener I assume you mean either the afterStart() or clusterChanged()?

The issue with this is that the requests are blocking requests. Do you recommend running these on a generic thread or as async requests?

With async requests it would require two one to check its existence and once to actually create the index.


(Alexander Reelsen) #4

the clusterChanged event may not be blocked, as it is called by an update thread for all registered listeners sequentially - thus you need to make sure in your own code that you a) run async, b) do not trigger a new async check for each cluster state update.

(system) #5

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.