# Plugin development - Node Client has not been initialized exception

**URL:** <https://discuss.elastic.co/t/plugin-development-node-client-has-not-been-initialized-exception/264239>\
**Category:** Elasticsearch\
**Created:** [February 14, 2021, 8:52am UTC](https://discuss.elastic.co/t/plugin-development-node-client-has-not-been-initialized-exception/264239 "2021-02-14T08:52:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tom\_Elias](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tom_elias/32/72245_2.png) [@Tom\_Elias](https://discuss.elastic.co/u/Tom_Elias)\
**Post date:** [February 14, 2021, 8:52am UTC](https://discuss.elastic.co/t/plugin-development-node-client-has-not-been-initialized-exception/264239/1 "2021-02-14T08:52:00Z")

</div>

Hello,  
i'm developing a plugin for elasticsearch 7.8.0 and i'm using the NodeClient to get all the mappings from the cluster on start-up, in order to find indices with "dense\_vector" field types.  
I am overriding the createComponents() method of the Plugin class since it is the only one that offers me the Client (node client) instance in its signature, but when i make a GetMapping request it throws an exception that "Node Client has not been initialized" and that is to be expected.

my question is if there is a flag like Cluster Health request i.e. "wait\_for\_status=true" for this kind of requests? for now i run in a while loop and catch the exceptions until it succeeds. (also note that calling Cluster Health fails with the same exception...)

thanks in advance,  
-- Tom Elias.

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [February 14, 2021, 1:48pm UTC](https://discuss.elastic.co/t/plugin-development-node-client-has-not-been-initialized-exception/264239/2 "2021-02-14T13:48:55Z")

</div>

A couple of possibilities off the top of my head:

1. If your plugin implements `LifecycleComponent` then its `start()` method is called once the client is initialised.

2. If you want to watch the cluster state for the mappings, you can use `ClusterService#addListener`

---

<div class="post-metadata">

**Author:** ![Tom\_Elias](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tom_elias/32/72245_2.png) [@Tom\_Elias](https://discuss.elastic.co/u/Tom_Elias)\
**Post date:** [February 14, 2021, 2:44pm UTC](https://discuss.elastic.co/t/plugin-development-node-client-has-not-been-initialized-exception/264239/3 "2021-02-14T14:44:55Z")

</div>

Hi David, Thanks for your reply.  
following up, does the start() method happen after all the shards have been initialized? (and the cluster status is \>= yellow?)  
i am also trying to figure out the timing of onIndexModule() method, because i want to add IndexOperationListeners to specific indices according to their mapping (if they include a dense\_vector or not)

Thanks,  
-- Tom Elias.

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [February 14, 2021, 5:16pm UTC](https://discuss.elastic.co/t/plugin-development-node-client-has-not-been-initialized-exception/264239/4 "2021-02-14T17:16:18Z")

</div>

> [@Tom\_Elias](#):
>
> does the start() method happen after all the shards have been initialized?

No, definitely not, components like plugins are started well before a master is elected, which in turn is well before any shards are started.

> [@Tom\_Elias](#):
>
> i am also trying to figure out the timing of onIndexModule() method

That happens much later too, but before shards are initialised.

---

<div class="post-metadata">

**Author:** ![Tom\_Elias](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tom_elias/32/72245_2.png) [@Tom\_Elias](https://discuss.elastic.co/u/Tom_Elias)\
**Post date:** [February 15, 2021, 8:45am UTC](https://discuss.elastic.co/t/plugin-development-node-client-has-not-been-initialized-exception/264239/5 "2021-02-15T08:45:51Z")

</div>

ok, so the way i see it, i would have to create a class extending a Listener during createComponents() and have it store a reference to the NodeClient, and install that listener on the ClusterService to run when the Cluster status becomes yellow.  
because, even though i am able to get the mapping before the NodeClient starts or the shards are initialized (during onIndexModule, by using reflection), i still need to scroll over those indices that i've found.

Thanks,  
-- Tom Elias.

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [February 15, 2021, 9:52am UTC](https://discuss.elastic.co/t/plugin-development-node-client-has-not-been-initialized-exception/264239/6 "2021-02-15T09:52:04Z")

</div>

I can't comment on whether this you have found absolutely the best approach, but certainly the intention of passing all that junk to `createComponents()` is so that you can capture it and use it later.

---

<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:** [March 15, 2021, 9:52am UTC](https://discuss.elastic.co/t/plugin-development-node-client-has-not-been-initialized-exception/264239/7 "2021-03-15T09:52:54Z")

</div>

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