Index creation on Plugin instantiation


(Thomas) #1

Hi,

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 overmentioned error, any ideas?

Thanks,

Thomas

--
Please update your bookmarks! We have moved to https://discuss.elastic.co/

You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/e7616e28-b6aa-45b0-989f-5ee7d55c02ca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(system) #2