0

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

tbo
  • 9,398
  • 8
  • 40
  • 51
  • Yes you are correct, the index create request failed because the cluster is not ready. While starting the es, plugins will load first before the cluster master detection you can see this in the INFO log of cluster. – Arun Prakash May 27 '15 at 09:58
  • I hope you should write an external job which may be invoked by the plugin to achieve this. – Arun Prakash May 27 '15 at 10:01
  • hi, thanks for the reply, what do you mean external job to be invoked? As an alternative way is there a way to ask whether the cluster is ready or not? so as I can postpone my index creation in a separate thread and when ready call index request? thanks!! – tbo May 27 '15 at 10:06

0 Answers0