# Index creation on Plugin instantiation

**URL:** <https://discuss.elastic.co/t/index-creation-on-plugin-instantiation/23689>\
**Category:** Elasticsearch\
**Created:** [May 26, 2015, 10:27am UTC](https://discuss.elastic.co/t/index-creation-on-plugin-instantiation/23689 "2015-05-26T10:27:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas\_Bolis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thomas_bolis/32/700_2.png) [@Thomas\_Bolis](https://discuss.elastic.co/u/Thomas_Bolis)\
**Post date:** [May 26, 2015, 10:27am UTC](https://discuss.elastic.co/t/index-creation-on-plugin-instantiation/23689/1 "2015-05-26T10:27:24Z")

</div>

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/](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](mailto: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](https://groups.google.com/d/msgid/elasticsearch/e7616e28-b6aa-45b0-989f-5ee7d55c02ca%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:11am UTC](https://discuss.elastic.co/t/index-creation-on-plugin-instantiation/23689/2 "2017-07-06T00:11:53Z")

</div>


