I'm experimenting with elasticsearch plugins creation and I'm trying to create an index (if missing) on plugin startup.
I wanted to ask what is the best place to add the code snippet for code creation? I have added it at an injected binding with Client as constructor parameter but i get the following error:
no known master node, scheduling a retry [2015-05-26 12:03:27,289][ERROR][bootstrap ] {1.4.1}: Initialization Failed ... 1) UncategorizedExecutionException[Failed execution] ExecutionException[java.lang.NullPointerException] NullPointerException
My guess is that Client is not ready yet to handle index creation requests, my code snippet is the following:
public class IndexCreator {
private final String indexName; private final ESLogger LOG; @Inject public IndexCreator(Settings settings, Client client) { this.LOG = Loggers.getLogger(getClass(), settings); this.indexName = settings.get("metis.index.name", ".metis"); String indexName = ".metis-registry"; IndicesExistsResponse resp = client.admin().indices().prepareExists(indexName).get(); if (!resp.isExists()) { client.admin().indices().prepareCreate(indexName).get(); } } }
And I add this as binding to my module
public class MyModule extends AbstractModule {
private final Settings settings; public MyModule(Settings settings) { this.settings = Preconditions.checkNotNull(settings); } @Override protected void configure() { bind(IndexCreator.class).asEagerSingleton(); } }
But it produces the over-mentioned error, any ideas? related post on groups here