# How can a plugin get a Client handle for the Node it's running in?

**URL:** <https://discuss.elastic.co/t/how-can-a-plugin-get-a-client-handle-for-the-node-its-running-in/10141>\
**Category:** Elasticsearch\
**Created:** [December 20, 2012, 10:13pm UTC](https://discuss.elastic.co/t/how-can-a-plugin-get-a-client-handle-for-the-node-its-running-in/10141 "2012-12-20T22:13:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeffrey\_Gerard](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@Jeffrey\_Gerard](https://discuss.elastic.co/u/Jeffrey_Gerard)\
**Post date:** [December 20, 2012, 10:13pm UTC](https://discuss.elastic.co/t/how-can-a-plugin-get-a-client-handle-for-the-node-its-running-in/10141/1 "2012-12-20T22:13:08Z")

</div>

I'm authoring an Elasticsearch plugin in java that will run inside each  
Elasticsearch node's same JVM. I can add REST endpoints and the like, but  
what's the best way to get a Client reference for the node I'm already  
running inside of?

I'm reluctant to use NodeBuilder.node().client() since that code appears to  
initialize everything required to add a new node to the cluster, which is  
not what I want. I just want a NodeClient of the node my plugin is already  
running on.

Thanks!

--

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [December 20, 2012, 10:22pm UTC](https://discuss.elastic.co/t/how-can-a-plugin-get-a-client-handle-for-the-node-its-running-in/10141/2 "2012-12-20T22:22:20Z")

</div>

When you bind an action to a module, the constructor should have an  
injected Client reference.

RestAction example:

> <https://github.com/brusic/elasticsearch-hello-world-plugin/blob/master/src/main/java/org/elasticsearch/rest/action/helloworld/HelloWorldAction.java>

River example:

> <https://github.com/elastic/elasticsearch-river-twitter/blob/master/src/main/java/org/elasticsearch/river/twitter/TwitterRiver.java>

AFAIK, from there, it is up to the TransportAction to be executed on each  
node and the TransportActions can communicate in various ways via the  
ClusterService. No need for the client at that point. At least, this is  
what I understood from reading the code. Not much is detailed of the inner  
workings.

--  
Ivan

On Thu, Dec 20, 2012 at 2:13 PM, Jeffrey Gerard [jgerard@climate.com](mailto:jgerard@climate.com) wrote:

> search plugin in java that will run inside each Elasticsearch node's sam

--

---

<div class="post-metadata">

**Author:** ![Jeffrey\_Gerard](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@Jeffrey\_Gerard](https://discuss.elastic.co/u/Jeffrey_Gerard)\
**Post date:** [December 20, 2012, 10:27pm UTC](https://discuss.elastic.co/t/how-can-a-plugin-get-a-client-handle-for-the-node-its-running-in/10141/3 "2012-12-20T22:27:38Z")

</div>

Indeed, there it is in the constructor. Perfect answer, thank you Ivan!

On Thursday, December 20, 2012 4:22:20 PM UTC-6, Ivan Brusic wrote:

> When you bind an action to a module, the constructor should have an  
> injected Client reference.
> 
> RestAction example:
> 
> [https://github.com/brusic/elasticsearch-hello-world-plugin/blob/master/src/main/java/org/elasticsearch/rest/action/helloworld/HelloWorldAction.java](https://github.com/brusic/elasticsearch-hello-world-plugin/blob/master/src/main/java/org/elasticsearch/rest/action/helloworld/HelloWorldAction.java)
> 
> River example:
> 
> [https://github.com/elasticsearch/elasticsearch-river-twitter/blob/master/src/main/java/org/elasticsearch/river/twitter/TwitterRiver.java](https://github.com/elasticsearch/elasticsearch-river-twitter/blob/master/src/main/java/org/elasticsearch/river/twitter/TwitterRiver.java)
> 
> AFAIK, from there, it is up to the TransportAction to be executed on each  
> node and the TransportActions can communicate in various ways via the  
> ClusterService. No need for the client at that point. At least, this is  
> what I understood from reading the code. Not much is detailed of the inner  
> workings.
> 
> --  
> Ivan
> 
> On Thu, Dec 20, 2012 at 2:13 PM, Jeffrey Gerard \<[jge...@climate.com](mailto:jge...@climate.com)\<javascript:\>
> 
> > wrote:
> 
> > search plugin in java that will run inside each Elasticsearch node's sam

--

---

<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, 2:58am UTC](https://discuss.elastic.co/t/how-can-a-plugin-get-a-client-handle-for-the-node-its-running-in/10141/4 "2017-07-06T02:58:57Z")

</div>


