# In ES 5.3.1 how can a plugin get a handle to the current Node?

**URL:** <https://discuss.elastic.co/t/in-es-5-3-1-how-can-a-plugin-get-a-handle-to-the-current-node/86720>\
**Category:** Elasticsearch\
**Created:** [May 22, 2017, 5:30pm UTC](https://discuss.elastic.co/t/in-es-5-3-1-how-can-a-plugin-get-a-handle-to-the-current-node/86720 "2017-05-22T17:30:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kusuma](https://avatars.discourse-cdn.com/v4/letter/k/8797f3/32.png) [@Kusuma](https://discuss.elastic.co/u/Kusuma)\
**Post date:** [May 22, 2017, 5:30pm UTC](https://discuss.elastic.co/t/in-es-5-3-1-how-can-a-plugin-get-a-handle-to-the-current-node/86720/1 "2017-05-22T17:30:53Z")

</div>

I have a plugin that was written for Elasticsearch version 2.3.2 similar to this one:

> <https://github.com/imotov/elasticsearch-native-script-example/blob/2.x/src/main/java/org/elasticsearch/examples/nativescript/script/LookupScript.java>

The script was registered with the plugin like this:

module.registerScript("lookup", LookupScript.Factory.class);

Reference: [https://github.com/imotov/elasticsearch-native-script-example/blob/2.x/src/main/java/org/elasticsearch/examples/nativescript/plugin/NativeScriptExamplesPlugin.java](https://github.com/imotov/elasticsearch-native-script-example/blob/2.x/src/main/java/org/elasticsearch/examples/nativescript/plugin/NativeScriptExamplesPlugin.java)

In version 5.3.1, the way to register the script with the plugin requires the script to be instantiated and it needs a handle to the Node.  
Like:  
@Override  
public List getNativeScripts() {  
return Arrays.asList(  
new LookupScript.Factory(node, this.settings); \<=== how to get node?  
);  
}

How do we get a handle to the current Node in the plugin?

Thank you!

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [May 23, 2017, 3:28am UTC](https://discuss.elastic.co/t/in-es-5-3-1-how-can-a-plugin-get-a-handle-to-the-current-node/86720/2 "2017-05-23T03:28:42Z")

</div>

Native scripts are deprecated in 5.x (next release 5.5.0). The documentation has been updated to explain how to [create a ScriptEngine](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/modules-scripting-engine.html) to get the same functionality. However, since 5.0, you are not able to do what that example is doing (get a node client). If you want to do that from a script engine (which you should not), you will have to create a client yourself.

---

<div class="post-metadata">

**Author:** ![Kusuma](https://avatars.discourse-cdn.com/v4/letter/k/8797f3/32.png) [@Kusuma](https://discuss.elastic.co/u/Kusuma)\
**Post date:** [May 23, 2017, 8:56pm UTC](https://discuss.elastic.co/t/in-es-5-3-1-how-can-a-plugin-get-a-handle-to-the-current-node/86720/3 "2017-05-23T20:56:26Z")

</div>

Thank you! I need to rework the script to not have to rely on the node client, since we also ran into some deadlock issues when trying to execute a search from the script.

---

<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:** [June 20, 2017, 8:56pm UTC](https://discuss.elastic.co/t/in-es-5-3-1-how-can-a-plugin-get-a-handle-to-the-current-node/86720/4 "2017-06-20T20:56:30Z")

</div>

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